Skip to content

Commit c68af43

Browse files
committed
Auto merge of #7916 - samueltardieu:double-colon-prefix, r=xFrednet
Advise to put a :: prefix inside the ticks Fixes #7914. changelog: Keep an initial `::` when [`doc_markdown`] suggests to use ticks
2 parents b6c8168 + 7f8198a commit c68af43

File tree

3 files changed

+64
-36
lines changed

3 files changed

+64
-36
lines changed

clippy_lints/src/doc.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,18 @@ fn check_text(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, text: &str
689689
for word in text.split(|c: char| c.is_whitespace() || c == '\'') {
690690
// Trim punctuation as in `some comment (see foo::bar).`
691691
// ^^
692-
// Or even as in `_foo bar_` which is emphasized.
693-
let word = word.trim_matches(|c: char| !c.is_alphanumeric());
692+
// Or even as in `_foo bar_` which is emphasized. Also preserve `::` as a prefix/suffix.
693+
let mut word = word.trim_matches(|c: char| !c.is_alphanumeric() && c != ':');
694694

695-
if valid_idents.contains(word) {
695+
// Remove leading or trailing single `:` which may be part of a sentence.
696+
if word.starts_with(':') && !word.starts_with("::") {
697+
word = word.trim_start_matches(':');
698+
}
699+
if word.ends_with(':') && !word.ends_with("::") {
700+
word = word.trim_end_matches(':');
701+
}
702+
703+
if valid_idents.contains(word) || word.chars().all(|c| c == ':') {
696704
continue;
697705
}
698706

tests/ui/doc/doc.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
/// The foo_bar function does _nothing_. See also foo::bar. (note the dot there)
99
/// Markdown is _weird_. I mean _really weird_. This \_ is ok. So is `_`. But not Foo::some_fun
1010
/// which should be reported only once despite being __doubly bad__.
11-
/// Here be ::a::global:path.
11+
/// Here be ::a::global:path, and _::another::global::path_. :: is not a path though.
12+
/// Import an item from ::awesome::global::blob:: (Intended postfix)
13+
/// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted)
1214
/// That's not code ~NotInCodeBlock~.
1315
/// be_sure_we_got_to_the_end_of_it
1416
fn foo_bar() {

tests/ui/doc/doc.stderr

+50-32
Original file line numberDiff line numberDiff line change
@@ -18,173 +18,191 @@ error: you should put `Foo::some_fun` between ticks in the documentation
1818
LL | /// Markdown is _weird_. I mean _really weird_. This /_ is ok. So is `_`. But not Foo::some_fun
1919
| ^^^^^^^^^^^^^
2020

21-
error: you should put `a::global:path` between ticks in the documentation
22-
--> $DIR/doc.rs:11:15
21+
error: you should put `::a::global:path` between ticks in the documentation
22+
--> $DIR/doc.rs:11:13
2323
|
24-
LL | /// Here be ::a::global:path.
25-
| ^^^^^^^^^^^^^^
24+
LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though.
25+
| ^^^^^^^^^^^^^^^^
26+
27+
error: you should put `::another::global::path` between ticks in the documentation
28+
--> $DIR/doc.rs:11:36
29+
|
30+
LL | /// Here be ::a::global:path, and _::another::global::path_. :: is not a path though.
31+
| ^^^^^^^^^^^^^^^^^^^^^^^
32+
33+
error: you should put `::awesome::global::blob::` between ticks in the documentation
34+
--> $DIR/doc.rs:12:25
35+
|
36+
LL | /// Import an item from ::awesome::global::blob:: (Intended postfix)
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
error: you should put `::Cat` between ticks in the documentation
40+
--> $DIR/doc.rs:13:31
41+
|
42+
LL | /// These are the options for ::Cat: (Intended trailing single colon, shouldn't be linted)
43+
| ^^^^^
2644

2745
error: you should put `NotInCodeBlock` between ticks in the documentation
28-
--> $DIR/doc.rs:12:22
46+
--> $DIR/doc.rs:14:22
2947
|
3048
LL | /// That's not code ~NotInCodeBlock~.
3149
| ^^^^^^^^^^^^^^
3250

3351
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
34-
--> $DIR/doc.rs:13:5
52+
--> $DIR/doc.rs:15:5
3553
|
3654
LL | /// be_sure_we_got_to_the_end_of_it
3755
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3856

3957
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
40-
--> $DIR/doc.rs:27:5
58+
--> $DIR/doc.rs:29:5
4159
|
4260
LL | /// be_sure_we_got_to_the_end_of_it
4361
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4462

4563
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
46-
--> $DIR/doc.rs:34:5
64+
--> $DIR/doc.rs:36:5
4765
|
4866
LL | /// be_sure_we_got_to_the_end_of_it
4967
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5068

5169
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
52-
--> $DIR/doc.rs:48:5
70+
--> $DIR/doc.rs:50:5
5371
|
5472
LL | /// be_sure_we_got_to_the_end_of_it
5573
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5674

5775
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
58-
--> $DIR/doc.rs:71:5
76+
--> $DIR/doc.rs:73:5
5977
|
6078
LL | /// be_sure_we_got_to_the_end_of_it
6179
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6280

6381
error: you should put `link_with_underscores` between ticks in the documentation
64-
--> $DIR/doc.rs:75:22
82+
--> $DIR/doc.rs:77:22
6583
|
6684
LL | /// This test has [a link_with_underscores][chunked-example] inside it. See #823.
6785
| ^^^^^^^^^^^^^^^^^^^^^
6886

6987
error: you should put `inline_link2` between ticks in the documentation
70-
--> $DIR/doc.rs:78:21
88+
--> $DIR/doc.rs:80:21
7189
|
7290
LL | /// It can also be [inline_link2].
7391
| ^^^^^^^^^^^^
7492

7593
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
76-
--> $DIR/doc.rs:88:5
94+
--> $DIR/doc.rs:90:5
7795
|
7896
LL | /// be_sure_we_got_to_the_end_of_it
7997
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8098

8199
error: you should put `CamelCaseThing` between ticks in the documentation
82-
--> $DIR/doc.rs:96:8
100+
--> $DIR/doc.rs:98:8
83101
|
84102
LL | /// ## CamelCaseThing
85103
| ^^^^^^^^^^^^^^
86104

87105
error: you should put `CamelCaseThing` between ticks in the documentation
88-
--> $DIR/doc.rs:99:7
106+
--> $DIR/doc.rs:101:7
89107
|
90108
LL | /// # CamelCaseThing
91109
| ^^^^^^^^^^^^^^
92110

93111
error: you should put `CamelCaseThing` between ticks in the documentation
94-
--> $DIR/doc.rs:101:22
112+
--> $DIR/doc.rs:103:22
95113
|
96114
LL | /// Not a title #897 CamelCaseThing
97115
| ^^^^^^^^^^^^^^
98116

99117
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
100-
--> $DIR/doc.rs:102:5
118+
--> $DIR/doc.rs:104:5
101119
|
102120
LL | /// be_sure_we_got_to_the_end_of_it
103121
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
104122

105123
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
106-
--> $DIR/doc.rs:109:5
124+
--> $DIR/doc.rs:111:5
107125
|
108126
LL | /// be_sure_we_got_to_the_end_of_it
109127
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
110128

111129
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
112-
--> $DIR/doc.rs:122:5
130+
--> $DIR/doc.rs:124:5
113131
|
114132
LL | /// be_sure_we_got_to_the_end_of_it
115133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
116134

117135
error: you should put `FooBar` between ticks in the documentation
118-
--> $DIR/doc.rs:133:43
136+
--> $DIR/doc.rs:135:43
119137
|
120138
LL | /** E.g., serialization of an empty list: FooBar
121139
| ^^^^^^
122140

123141
error: you should put `BarQuz` between ticks in the documentation
124-
--> $DIR/doc.rs:138:5
142+
--> $DIR/doc.rs:140:5
125143
|
126144
LL | And BarQuz too.
127145
| ^^^^^^
128146

129147
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
130-
--> $DIR/doc.rs:139:1
148+
--> $DIR/doc.rs:141:1
131149
|
132150
LL | be_sure_we_got_to_the_end_of_it
133151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134152

135153
error: you should put `FooBar` between ticks in the documentation
136-
--> $DIR/doc.rs:144:43
154+
--> $DIR/doc.rs:146:43
137155
|
138156
LL | /** E.g., serialization of an empty list: FooBar
139157
| ^^^^^^
140158

141159
error: you should put `BarQuz` between ticks in the documentation
142-
--> $DIR/doc.rs:149:5
160+
--> $DIR/doc.rs:151:5
143161
|
144162
LL | And BarQuz too.
145163
| ^^^^^^
146164

147165
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
148-
--> $DIR/doc.rs:150:1
166+
--> $DIR/doc.rs:152:1
149167
|
150168
LL | be_sure_we_got_to_the_end_of_it
151169
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152170

153171
error: you should put `be_sure_we_got_to_the_end_of_it` between ticks in the documentation
154-
--> $DIR/doc.rs:161:5
172+
--> $DIR/doc.rs:163:5
155173
|
156174
LL | /// be_sure_we_got_to_the_end_of_it
157175
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
158176

159177
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
160-
--> $DIR/doc.rs:188:13
178+
--> $DIR/doc.rs:190:13
161179
|
162180
LL | /// Not ok: http://www.unicode.org
163181
| ^^^^^^^^^^^^^^^^^^^^^^
164182

165183
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
166-
--> $DIR/doc.rs:189:13
184+
--> $DIR/doc.rs:191:13
167185
|
168186
LL | /// Not ok: https://www.unicode.org
169187
| ^^^^^^^^^^^^^^^^^^^^^^^
170188

171189
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
172-
--> $DIR/doc.rs:190:13
190+
--> $DIR/doc.rs:192:13
173191
|
174192
LL | /// Not ok: http://www.unicode.org/
175193
| ^^^^^^^^^^^^^^^^^^^^^^
176194

177195
error: you should put bare URLs between `<`/`>` or make a proper Markdown link
178-
--> $DIR/doc.rs:191:13
196+
--> $DIR/doc.rs:193:13
179197
|
180198
LL | /// Not ok: http://www.unicode.org/reports/tr9/#Reordering_Resolved_Levels
181199
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
182200

183201
error: you should put `mycrate::Collection` between ticks in the documentation
184-
--> $DIR/doc.rs:194:22
202+
--> $DIR/doc.rs:196:22
185203
|
186204
LL | /// An iterator over mycrate::Collection's values.
187205
| ^^^^^^^^^^^^^^^^^^^
188206

189-
error: aborting due to 31 previous errors
207+
error: aborting due to 34 previous errors
190208

0 commit comments

Comments
 (0)