diff options
| author | Jason Newcomb <jsnewcomb@pm.me> | 2024-12-03 15:53:46 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-03 15:53:46 +0000 |
| commit | 19426bfdfb430c1a423c56160e120f95e8548e3d (patch) | |
| tree | 38c464ac0d2912c98a08eeef8ef4b6b5d86cb42c | |
| parent | 646d72a01dda7224e7bf8c39a0b0451f112b1226 (diff) | |
| parent | d3a7fb140c539be677db2ef0f7f93f6b5d0a19f1 (diff) | |
| download | rust-19426bfdfb430c1a423c56160e120f95e8548e3d.tar.gz rust-19426bfdfb430c1a423c56160e120f95e8548e3d.zip | |
doc_lazy_continuation: Correctly count indent with backslashes (#13742)
changelog: [`doc_lazy_continuation`]: correctly count indent with backslashes Fixes #13705
| -rw-r--r-- | clippy_lints/src/doc/mod.rs | 7 | ||||
| -rw-r--r-- | tests/ui/doc/doc_lazy_list.fixed | 6 | ||||
| -rw-r--r-- | tests/ui/doc/doc_lazy_list.rs | 6 |
3 files changed, 18 insertions, 1 deletions
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 2439ee23758..46571246052 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -948,7 +948,12 @@ fn check_doc<'a, Events: Iterator<Item = (pulldown_cmark::Event<'a>, Range<usize ); refdefrange.start - range.start } else { - next_range.start - range.start + let mut start = next_range.start; + if start > 0 && doc.as_bytes().get(start - 1) == Some(&b'\\') { + // backslashes aren't in the event stream... + start -= 1; + } + start - range.start } } else { 0 diff --git a/tests/ui/doc/doc_lazy_list.fixed b/tests/ui/doc/doc_lazy_list.fixed index da537518a2b..0822cc7c635 100644 --- a/tests/ui/doc/doc_lazy_list.fixed +++ b/tests/ui/doc/doc_lazy_list.fixed @@ -75,3 +75,9 @@ fn seven() {} /// ] //~^ ERROR: doc list item without indentation fn eight() {} + +#[rustfmt::skip] +// https://github.com/rust-lang/rust-clippy/issues/13705 +/// - \[text in square brackets\] with a long following description +/// that goes over multiple lines +pub fn backslash_escaped_square_braces() {} diff --git a/tests/ui/doc/doc_lazy_list.rs b/tests/ui/doc/doc_lazy_list.rs index 3cc18e35780..068de140e00 100644 --- a/tests/ui/doc/doc_lazy_list.rs +++ b/tests/ui/doc/doc_lazy_list.rs @@ -75,3 +75,9 @@ fn seven() {} /// ] //~^ ERROR: doc list item without indentation fn eight() {} + +#[rustfmt::skip] +// https://github.com/rust-lang/rust-clippy/issues/13705 +/// - \[text in square brackets\] with a long following description +/// that goes over multiple lines +pub fn backslash_escaped_square_braces() {} |
