Skip to content

Commit a966712

Browse files
committed
doc_lazy_continuation: Correctly count indent with backslashes
changelog: [`doc_lazy_continuation`]: correctly count indent with backslashes
1 parent b4163f0 commit a966712

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,12 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize
871871
}
872872
if let Start(Item) = event {
873873
if let Some((_next_event, next_range)) = events.peek() {
874-
containers.push(Container::List(next_range.start - range.start));
874+
let mut start = next_range.start;
875+
if start > 0 && doc.as_bytes().get(start - 1) == Some(&b'\\') {
876+
// backslashes aren't in the event stream...
877+
start -= 1;
878+
}
879+
containers.push(Container::List(start - range.start));
875880
} else {
876881
containers.push(Container::List(0));
877882
}

tests/ui/doc/doc_lazy_list.fixed

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,9 @@ fn seven() {}
7575
/// ]
7676
//~^ ERROR: doc list item without indentation
7777
fn eight() {}
78+
79+
#[rustfmt::skip]
80+
// https://github.com/rust-lang/rust-clippy/issues/13705
81+
/// - \[text in square brackets\] with a long following description
82+
/// that goes over multiple lines
83+
pub fn backslash_escaped_square_braces() {}

tests/ui/doc/doc_lazy_list.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,9 @@ fn seven() {}
7575
/// ]
7676
//~^ ERROR: doc list item without indentation
7777
fn eight() {}
78+
79+
#[rustfmt::skip]
80+
// https://github.com/rust-lang/rust-clippy/issues/13705
81+
/// - \[text in square brackets\] with a long following description
82+
/// that goes over multiple lines
83+
pub fn backslash_escaped_square_braces() {}

0 commit comments

Comments
 (0)