Skip to content

Commit

Permalink
Advise to put a :: prefix inside the ticks
Browse files Browse the repository at this point in the history
  • Loading branch information
samueltardieu committed Nov 2, 2021
1 parent 18cc4e7 commit 2a1ba1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
11 changes: 10 additions & 1 deletion clippy_lints/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,16 @@ fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str
// Trim punctuation as in `some comment (see foo::bar).`
// ^^
// Or even as in `_foo bar_` which is emphasized.
let word = word.trim_matches(|c: char| !c.is_alphanumeric());
let word = {
let w = word.trim_matches(|c: char| !c.is_alphanumeric());
let offset = w.as_ptr() as usize - word.as_ptr() as usize;
// Preserve an initial `::` prefix, even as in `_::a::b_` which is emphasized.
if offset >= 2 && word.as_bytes()[offset - 2] == b':' && word.as_bytes()[offset - 1] == b':' {
&word[offset - 2..offset + w.len()]
} else {
w
}
};

if valid_idents.contains(word) {
continue;
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/doc/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun
/// which should be reported only once despite being __doubly bad__.
/// Here be ::a::global:path.
/// Here be ::a::global:path and _::another::global::path_.
/// That's not code ~NotInCodeBlock~.
/// be_sure_we_got_to_the_end_of_it
fn foo_bar() {
Expand Down
16 changes: 11 additions & 5 deletions tests/ui/doc/doc.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ error: you should put `Foo::some_fun` between ticks in the documentation
LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun
| ^^^^^^^^^^^^^

error: you should put `a::global:path` between ticks in the documentation
--> $DIR/doc.rs:11:15
error: you should put `::a::global:path` between ticks in the documentation
--> $DIR/doc.rs:11:13
|
LL | /// Here be ::a::global:path.
| ^^^^^^^^^^^^^^
LL | /// Here be ::a::global:path and _::another::global::path_.
| ^^^^^^^^^^^^^^^^

error: you should put `::another::global::path` between ticks in the documentation
--> $DIR/doc.rs:11:35
|
LL | /// Here be ::a::global:path and _::another::global::path_.
| ^^^^^^^^^^^^^^^^^^^^^^^

error: you should put `NotInCodeBlock` between ticks in the documentation
--> $DIR/doc.rs:12:22
Expand Down Expand Up @@ -186,5 +192,5 @@ error: you should put `mycrate::Collection` between ticks in the documentation
LL | /// An iterator over mycrate::Collection's values.
| ^^^^^^^^^^^^^^^^^^^

error: aborting due to 31 previous errors
error: aborting due to 32 previous errors

0 comments on commit 2a1ba1e

Please sign in to comment.