File tree 4 files changed +86
-0
lines changed
4 files changed +86
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ pub fn check(
30
30
word = tmp_word;
31
31
}
32
32
33
+ let original_len = word. len ( ) ;
33
34
word = word. trim_start_matches ( trim_pattern) ;
34
35
35
36
// Remove leading or trailing single `:` which may be part of a sentence.
@@ -44,6 +45,25 @@ pub fn check(
44
45
continue ;
45
46
}
46
47
48
+ // Ensure that all reachable matching closing parens are included as well.
49
+ let size_diff = original_len - word. len ( ) ;
50
+ let mut open_parens = 0 ;
51
+ let mut close_parens = 0 ;
52
+ for c in word. chars ( ) {
53
+ if c == '(' {
54
+ open_parens += 1 ;
55
+ } else if c == ')' {
56
+ close_parens += 1 ;
57
+ }
58
+ }
59
+ while close_parens < open_parens
60
+ && let Some ( tmp_word) = orig_word. get ( size_diff..=( word. len ( ) + size_diff) )
61
+ && tmp_word. ends_with ( ')' )
62
+ {
63
+ word = tmp_word;
64
+ close_parens += 1 ;
65
+ }
66
+
47
67
// Adjust for the current word
48
68
let offset = word. as_ptr ( ) as usize - text. as_ptr ( ) as usize ;
49
69
let span = Span :: new (
Original file line number Diff line number Diff line change
1
+ #![warn(clippy::doc_markdown)]
2
+
3
+ //! A comment with `a_b(x)` and `a_c` in it and (`a_b((c))` ) too and (maybe `a_b((c))`)
4
+ //~^ ERROR: item in documentation is missing backticks
5
+ //~| ERROR: item in documentation is missing backticks
6
+ //~| ERROR: item in documentation is missing backticks
7
+ //~| ERROR: item in documentation is missing backticks
8
+
9
+ pub fn main() {}
Original file line number Diff line number Diff line change
1
+ #![ warn( clippy:: doc_markdown) ]
2
+
3
+ //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
4
+ //~^ ERROR: item in documentation is missing backticks
5
+ //~| ERROR: item in documentation is missing backticks
6
+ //~| ERROR: item in documentation is missing backticks
7
+ //~| ERROR: item in documentation is missing backticks
8
+
9
+ pub fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: item in documentation is missing backticks
2
+ --> tests/ui/doc/issue_12795.rs:3:20
3
+ |
4
+ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
5
+ | ^^^^^^
6
+ |
7
+ = note: `-D clippy::doc-markdown` implied by `-D warnings`
8
+ = help: to override `-D warnings` add `#[allow(clippy::doc_markdown)]`
9
+ help: try
10
+ |
11
+ LL | //! A comment with `a_b(x)` and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
12
+ | ~~~~~~~~
13
+
14
+ error: item in documentation is missing backticks
15
+ --> tests/ui/doc/issue_12795.rs:3:31
16
+ |
17
+ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
18
+ | ^^^
19
+ |
20
+ help: try
21
+ |
22
+ LL | //! A comment with a_b(x) and `a_c` in it and (a_b((c)) ) too and (maybe a_b((c)))
23
+ | ~~~~~
24
+
25
+ error: item in documentation is missing backticks
26
+ --> tests/ui/doc/issue_12795.rs:3:46
27
+ |
28
+ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
29
+ | ^^^^^^^^
30
+ |
31
+ help: try
32
+ |
33
+ LL | //! A comment with a_b(x) and a_c in it and (`a_b((c))` ) too and (maybe a_b((c)))
34
+ | ~~~~~~~~~~
35
+
36
+ error: item in documentation is missing backticks
37
+ --> tests/ui/doc/issue_12795.rs:3:72
38
+ |
39
+ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe a_b((c)))
40
+ | ^^^^^^^^
41
+ |
42
+ help: try
43
+ |
44
+ LL | //! A comment with a_b(x) and a_c in it and (a_b((c)) ) too and (maybe `a_b((c))`)
45
+ | ~~~~~~~~~~
46
+
47
+ error: aborting due to 4 previous errors
48
+
You can’t perform that action at this time.
0 commit comments