diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2025-07-01 22:31:15 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-01 22:31:15 +0000 |
| commit | ebdbd7cfc0666af309c0b76424f01c44b5f8bccb (patch) | |
| tree | dcd4246afe1600cc5185608a960b2053ac4e0269 | |
| parent | ad15b600227dd8fc95915d3b23d131f2dfb9ff7a (diff) | |
| parent | 664b143dac42362bebdd93ea1a864c21bac5dd4d (diff) | |
| download | rust-ebdbd7cfc0666af309c0b76424f01c44b5f8bccb.tar.gz rust-ebdbd7cfc0666af309c0b76424f01c44b5f8bccb.zip | |
doc_nested_refdefs: do not falsely report checkboxes as refdefs (#15146)
changelog: [`doc_nested_refdefs`]: fix false positive where [task lists](http://pulldown-cmark.github.io/pulldown-cmark/third_party/gfm_tasklist.html) are reported as refdefs
| -rw-r--r-- | clippy_lints/src/doc/mod.rs | 4 | ||||
| -rw-r--r-- | tests/ui/doc/doc_nested_refdef_list_item.fixed | 6 | ||||
| -rw-r--r-- | tests/ui/doc/doc_nested_refdef_list_item.rs | 2 | ||||
| -rw-r--r-- | tests/ui/doc/doc_nested_refdef_list_item.stderr | 26 |
4 files changed, 6 insertions, 32 deletions
diff --git a/clippy_lints/src/doc/mod.rs b/clippy_lints/src/doc/mod.rs index 1b6c48e53f5..49397938ca7 100644 --- a/clippy_lints/src/doc/mod.rs +++ b/clippy_lints/src/doc/mod.rs @@ -1249,7 +1249,9 @@ fn looks_like_refdef(doc: &str, range: Range<usize>) -> Option<Range<usize>> { b'[' => { start = Some(i + offset); }, - b']' if let Some(start) = start => { + b']' if let Some(start) = start + && doc.as_bytes().get(i + offset + 1) == Some(&b':') => + { return Some(start..i + offset + 1); }, _ => {}, diff --git a/tests/ui/doc/doc_nested_refdef_list_item.fixed b/tests/ui/doc/doc_nested_refdef_list_item.fixed index 065f4486e39..5c57c58fbc0 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.fixed +++ b/tests/ui/doc/doc_nested_refdef_list_item.fixed @@ -72,8 +72,6 @@ pub struct NotEmptyTight; /// ## Heading /// -/// - [x][] - Done -//~^ ERROR: link reference defined in list item -/// - [ ][] - Not Done -//~^ ERROR: link reference defined in list item +/// - [x] - Done +/// - [ ] - Not Done pub struct GithubCheckboxes; diff --git a/tests/ui/doc/doc_nested_refdef_list_item.rs b/tests/ui/doc/doc_nested_refdef_list_item.rs index c7eab50c8b3..06b6ba49e19 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.rs +++ b/tests/ui/doc/doc_nested_refdef_list_item.rs @@ -73,7 +73,5 @@ pub struct NotEmptyTight; /// ## Heading /// /// - [x] - Done -//~^ ERROR: link reference defined in list item /// - [ ] - Not Done -//~^ ERROR: link reference defined in list item pub struct GithubCheckboxes; diff --git a/tests/ui/doc/doc_nested_refdef_list_item.stderr b/tests/ui/doc/doc_nested_refdef_list_item.stderr index 5a815dabf4d..27314c7e968 100644 --- a/tests/ui/doc/doc_nested_refdef_list_item.stderr +++ b/tests/ui/doc/doc_nested_refdef_list_item.stderr @@ -144,29 +144,5 @@ help: for an intra-doc link, add `[]` between the label and the colon LL | /// - [link][]: def "title" | ++ -error: link reference defined in list item - --> tests/ui/doc/doc_nested_refdef_list_item.rs:75:7 - | -LL | /// - [x] - Done - | ^^^ - | - = help: link definitions are not shown in rendered documentation -help: for an intra-doc link, add `[]` between the label and the colon - | -LL | /// - [x][] - Done - | ++ - -error: link reference defined in list item - --> tests/ui/doc/doc_nested_refdef_list_item.rs:77:7 - | -LL | /// - [ ] - Not Done - | ^^^ - | - = help: link definitions are not shown in rendered documentation -help: for an intra-doc link, add `[]` between the label and the colon - | -LL | /// - [ ][] - Not Done - | ++ - -error: aborting due to 14 previous errors +error: aborting due to 12 previous errors |
