Skip to content

Commit 664b143

Browse files
committed
doc_nested_refdefs: do not falsely report checkboxes as refdefs
1 parent 7546381 commit 664b143

File tree

4 files changed

+6
-32
lines changed

4 files changed

+6
-32
lines changed

clippy_lints/src/doc/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,9 @@ fn looks_like_refdef(doc: &str, range: Range<usize>) -> Option<Range<usize>> {
12491249
b'[' => {
12501250
start = Some(i + offset);
12511251
},
1252-
b']' if let Some(start) = start => {
1252+
b']' if let Some(start) = start
1253+
&& doc.as_bytes().get(i + offset + 1) == Some(&b':') =>
1254+
{
12531255
return Some(start..i + offset + 1);
12541256
},
12551257
_ => {},

tests/ui/doc/doc_nested_refdef_list_item.fixed

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ pub struct NotEmptyTight;
7272

7373
/// ## Heading
7474
///
75-
/// - [x][] - Done
76-
//~^ ERROR: link reference defined in list item
77-
/// - [ ][] - Not Done
78-
//~^ ERROR: link reference defined in list item
75+
/// - [x] - Done
76+
/// - [ ] - Not Done
7977
pub struct GithubCheckboxes;

tests/ui/doc/doc_nested_refdef_list_item.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,5 @@ pub struct NotEmptyTight;
7373
/// ## Heading
7474
///
7575
/// - [x] - Done
76-
//~^ ERROR: link reference defined in list item
7776
/// - [ ] - Not Done
78-
//~^ ERROR: link reference defined in list item
7977
pub struct GithubCheckboxes;

tests/ui/doc/doc_nested_refdef_list_item.stderr

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,5 @@ help: for an intra-doc link, add `[]` between the label and the colon
144144
LL | /// - [link][]: def "title"
145145
| ++
146146

147-
error: link reference defined in list item
148-
--> tests/ui/doc/doc_nested_refdef_list_item.rs:75:7
149-
|
150-
LL | /// - [x] - Done
151-
| ^^^
152-
|
153-
= help: link definitions are not shown in rendered documentation
154-
help: for an intra-doc link, add `[]` between the label and the colon
155-
|
156-
LL | /// - [x][] - Done
157-
| ++
158-
159-
error: link reference defined in list item
160-
--> tests/ui/doc/doc_nested_refdef_list_item.rs:77:7
161-
|
162-
LL | /// - [ ] - Not Done
163-
| ^^^
164-
|
165-
= help: link definitions are not shown in rendered documentation
166-
help: for an intra-doc link, add `[]` between the label and the colon
167-
|
168-
LL | /// - [ ][] - Not Done
169-
| ++
170-
171-
error: aborting due to 14 previous errors
147+
error: aborting due to 12 previous errors
172148

0 commit comments

Comments
 (0)