Skip to content

Commit b5cf8b8

Browse files
committed
doc_lazy_continuation: do not warn on End events
This avoids event spans that would otherwise cause crashes, since an End's span covers the range of the tag (which will be earlier than the line break within the tag).
1 parent 680256f commit b5cf8b8

File tree

4 files changed

+97
-2
lines changed

4 files changed

+97
-2
lines changed

clippy_lints/src/doc/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -750,10 +750,11 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
750750
Start(_tag) | End(_tag) => (), // We don't care about other tags
751751
SoftBreak | HardBreak => {
752752
if !containers.is_empty()
753-
&& let Some((_next_event, next_range)) = events.peek()
753+
&& let Some((next_event, next_range)) = events.peek()
754754
&& let Some(next_span) = fragments.span(cx, next_range.clone())
755755
&& let Some(span) = fragments.span(cx, range.clone())
756756
&& !in_footnote_definition
757+
&& !matches!(next_event, End(_))
757758
{
758759
lazy_continuation::check(
759760
cx,

tests/ui/doc/doc_lazy_list.fixed

+35
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,38 @@ fn six() {}
4040
///
4141
/// this is not a lazy continuation
4242
fn seven() {}
43+
44+
#[rustfmt::skip]
45+
// https://github.com/rust-lang/rust-clippy/pull/12770#issuecomment-2118601768
46+
/// Returns a list of ProtocolDescriptors from a Serde JSON input.
47+
///
48+
/// Defined Protocol Identifiers for the Protocol Descriptor
49+
/// We intentionally omit deprecated profile identifiers.
50+
/// From Bluetooth Assigned Numbers:
51+
/// https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
52+
///
53+
/// # Arguments
54+
/// * `protocol_descriptors`: A Json Representation of the ProtocolDescriptors
55+
/// to set up. Example:
56+
/// 'protocol_descriptors': [
57+
//~^ ERROR: doc list item missing indentation
58+
/// {
59+
/// 'protocol': 25, # u64 Representation of ProtocolIdentifier::AVDTP
60+
/// 'params': [
61+
/// {
62+
/// 'data': 0x0103 # to indicate 1.3
63+
/// },
64+
/// {
65+
/// 'data': 0x0105 # to indicate 1.5
66+
/// }
67+
/// ]
68+
/// },
69+
/// {
70+
/// 'protocol': 1, # u64 Representation of ProtocolIdentifier::SDP
71+
/// 'params': [{
72+
/// 'data': 0x0019
73+
/// }]
74+
/// }
75+
/// ]
76+
//~^ ERROR: doc list item missing indentation
77+
fn eight() {}

tests/ui/doc/doc_lazy_list.rs

+35
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,38 @@ fn six() {}
4040
///
4141
/// this is not a lazy continuation
4242
fn seven() {}
43+
44+
#[rustfmt::skip]
45+
// https://github.com/rust-lang/rust-clippy/pull/12770#issuecomment-2118601768
46+
/// Returns a list of ProtocolDescriptors from a Serde JSON input.
47+
///
48+
/// Defined Protocol Identifiers for the Protocol Descriptor
49+
/// We intentionally omit deprecated profile identifiers.
50+
/// From Bluetooth Assigned Numbers:
51+
/// https://www.bluetooth.com/specifications/assigned-numbers/service-discovery
52+
///
53+
/// # Arguments
54+
/// * `protocol_descriptors`: A Json Representation of the ProtocolDescriptors
55+
/// to set up. Example:
56+
/// 'protocol_descriptors': [
57+
//~^ ERROR: doc list item missing indentation
58+
/// {
59+
/// 'protocol': 25, # u64 Representation of ProtocolIdentifier::AVDTP
60+
/// 'params': [
61+
/// {
62+
/// 'data': 0x0103 # to indicate 1.3
63+
/// },
64+
/// {
65+
/// 'data': 0x0105 # to indicate 1.5
66+
/// }
67+
/// ]
68+
/// },
69+
/// {
70+
/// 'protocol': 1, # u64 Representation of ProtocolIdentifier::SDP
71+
/// 'params': [{
72+
/// 'data': 0x0019
73+
/// }]
74+
/// }
75+
/// ]
76+
//~^ ERROR: doc list item missing indentation
77+
fn eight() {}

tests/ui/doc/doc_lazy_list.stderr

+25-1
Original file line numberDiff line numberDiff line change
@@ -108,5 +108,29 @@ help: indent this line
108108
LL | /// and so should this
109109
| ++
110110

111-
error: aborting due to 9 previous errors
111+
error: doc list item missing indentation
112+
--> tests/ui/doc/doc_lazy_list.rs:56:5
113+
|
114+
LL | /// 'protocol_descriptors': [
115+
| ^
116+
|
117+
= help: if this is supposed to be its own paragraph, add a blank line
118+
help: indent this line
119+
|
120+
LL | /// 'protocol_descriptors': [
121+
| +
122+
123+
error: doc list item missing indentation
124+
--> tests/ui/doc/doc_lazy_list.rs:75:5
125+
|
126+
LL | /// ]
127+
| ^
128+
|
129+
= help: if this is supposed to be its own paragraph, add a blank line
130+
help: indent this line
131+
|
132+
LL | /// ]
133+
| +
134+
135+
error: aborting due to 11 previous errors
112136

0 commit comments

Comments
 (0)