Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit bb0fd66

Browse files
committedDec 12, 2023
Follow guidelines for lint suggestions
1 parent 98aa20b commit bb0fd66

File tree

4 files changed

+76
-36
lines changed

4 files changed

+76
-36
lines changed
 

‎src/librustdoc/html/markdown.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
//! ```
2828
2929
use rustc_data_structures::fx::FxHashMap;
30-
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
30+
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage};
3131
use rustc_hir::def_id::DefId;
3232
use rustc_middle::ty::TyCtxt;
3333
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
@@ -843,15 +843,17 @@ impl<'tcx> ExtraInfo<'tcx> {
843843
fn error_invalid_codeblock_attr_with_help(
844844
&self,
845845
msg: impl Into<DiagnosticMessage>,
846-
help: impl Into<SubdiagnosticMessage>,
846+
f: impl for<'a, 'b> FnOnce(
847+
&'b mut DiagnosticBuilder<'a, ()>,
848+
) -> &'b mut DiagnosticBuilder<'a, ()>,
847849
) {
848850
if let Some(def_id) = self.def_id.as_local() {
849851
self.tcx.struct_span_lint_hir(
850852
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
851853
self.tcx.local_def_id_to_hir_id(def_id),
852854
self.sp,
853855
msg,
854-
|lint| lint.help(help),
856+
f,
855857
);
856858
}
857859
}
@@ -1288,10 +1290,15 @@ impl LangString {
12881290
if x.starts_with("rust") && x[4..].parse::<Edition>().is_ok() =>
12891291
{
12901292
if let Some(extra) = extra {
1291-
extra.error_invalid_codeblock_attr(format!(
1292-
"unknown attribute `{x}`. Did you mean `edition{}`?",
1293-
&x[4..]
1294-
));
1293+
extra.error_invalid_codeblock_attr_with_help(
1294+
format!("unknown attribute `{x}`"),
1295+
|lint| {
1296+
lint.help(format!(
1297+
"there is an attribute with a similar name: `edition{}`",
1298+
&x[4..],
1299+
))
1300+
},
1301+
);
12951302
}
12961303
}
12971304
LangStringToken::LangToken(x)
@@ -1338,8 +1345,13 @@ impl LangString {
13381345
} {
13391346
if let Some(extra) = extra {
13401347
extra.error_invalid_codeblock_attr_with_help(
1341-
format!("unknown attribute `{x}`. Did you mean `{flag}`?"),
1342-
help,
1348+
format!("unknown attribute `{x}`"),
1349+
|lint| {
1350+
lint.help(format!(
1351+
"there is an attribute with a similar name: `{flag}`"
1352+
))
1353+
.help(help)
1354+
},
13431355
);
13441356
}
13451357
}

‎tests/rustdoc-ui/doctest/check-attr-test.stderr

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
1+
error: unknown attribute `compile-fail`
22
--> $DIR/check-attr-test.rs:5:1
33
|
44
5 | / /// foo
@@ -8,14 +8,15 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
88
9 | | /// ```
99
| |_______^
1010
|
11+
= help: there is an attribute with a similar name: `compile_fail`
1112
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
1213
note: the lint level is defined here
1314
--> $DIR/check-attr-test.rs:3:9
1415
|
1516
3 | #![deny(rustdoc::invalid_codeblock_attributes)]
1617
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1718

18-
error: unknown attribute `compilefail`. Did you mean `compile_fail`?
19+
error: unknown attribute `compilefail`
1920
--> $DIR/check-attr-test.rs:5:1
2021
|
2122
5 | / /// foo
@@ -25,9 +26,10 @@ error: unknown attribute `compilefail`. Did you mean `compile_fail`?
2526
9 | | /// ```
2627
| |_______^
2728
|
29+
= help: there is an attribute with a similar name: `compile_fail`
2830
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
2931

30-
error: unknown attribute `comPile_fail`. Did you mean `compile_fail`?
32+
error: unknown attribute `comPile_fail`
3133
--> $DIR/check-attr-test.rs:5:1
3234
|
3335
5 | / /// foo
@@ -37,9 +39,10 @@ error: unknown attribute `comPile_fail`. Did you mean `compile_fail`?
3739
9 | | /// ```
3840
| |_______^
3941
|
42+
= help: there is an attribute with a similar name: `compile_fail`
4043
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
4144

42-
error: unknown attribute `should-panic`. Did you mean `should_panic`?
45+
error: unknown attribute `should-panic`
4346
--> $DIR/check-attr-test.rs:12:1
4447
|
4548
12 | / /// bar
@@ -49,9 +52,10 @@ error: unknown attribute `should-panic`. Did you mean `should_panic`?
4952
16 | | /// ```
5053
| |_______^
5154
|
55+
= help: there is an attribute with a similar name: `should_panic`
5256
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
5357

54-
error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
58+
error: unknown attribute `shouldpanic`
5559
--> $DIR/check-attr-test.rs:12:1
5660
|
5761
12 | / /// bar
@@ -61,9 +65,10 @@ error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
6165
16 | | /// ```
6266
| |_______^
6367
|
68+
= help: there is an attribute with a similar name: `should_panic`
6469
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
6570

66-
error: unknown attribute `shOuld_panic`. Did you mean `should_panic`?
71+
error: unknown attribute `shOuld_panic`
6772
--> $DIR/check-attr-test.rs:12:1
6873
|
6974
12 | / /// bar
@@ -73,9 +78,10 @@ error: unknown attribute `shOuld_panic`. Did you mean `should_panic`?
7378
16 | | /// ```
7479
| |_______^
7580
|
81+
= help: there is an attribute with a similar name: `should_panic`
7682
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
7783

78-
error: unknown attribute `no-run`. Did you mean `no_run`?
84+
error: unknown attribute `no-run`
7985
--> $DIR/check-attr-test.rs:19:1
8086
|
8187
19 | / /// foobar
@@ -85,9 +91,10 @@ error: unknown attribute `no-run`. Did you mean `no_run`?
8591
23 | | /// ```
8692
| |_______^
8793
|
94+
= help: there is an attribute with a similar name: `no_run`
8895
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
8996

90-
error: unknown attribute `norun`. Did you mean `no_run`?
97+
error: unknown attribute `norun`
9198
--> $DIR/check-attr-test.rs:19:1
9299
|
93100
19 | / /// foobar
@@ -97,9 +104,10 @@ error: unknown attribute `norun`. Did you mean `no_run`?
97104
23 | | /// ```
98105
| |_______^
99106
|
107+
= help: there is an attribute with a similar name: `no_run`
100108
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
101109

102-
error: unknown attribute `nO_run`. Did you mean `no_run`?
110+
error: unknown attribute `nO_run`
103111
--> $DIR/check-attr-test.rs:19:1
104112
|
105113
19 | / /// foobar
@@ -109,9 +117,10 @@ error: unknown attribute `nO_run`. Did you mean `no_run`?
109117
23 | | /// ```
110118
| |_______^
111119
|
120+
= help: there is an attribute with a similar name: `no_run`
112121
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
113122

114-
error: unknown attribute `test-harness`. Did you mean `test_harness`?
123+
error: unknown attribute `test-harness`
115124
--> $DIR/check-attr-test.rs:26:1
116125
|
117126
26 | / /// b
@@ -121,9 +130,10 @@ error: unknown attribute `test-harness`. Did you mean `test_harness`?
121130
30 | | /// ```
122131
| |_______^
123132
|
133+
= help: there is an attribute with a similar name: `test_harness`
124134
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
125135

126-
error: unknown attribute `testharness`. Did you mean `test_harness`?
136+
error: unknown attribute `testharness`
127137
--> $DIR/check-attr-test.rs:26:1
128138
|
129139
26 | / /// b
@@ -133,9 +143,10 @@ error: unknown attribute `testharness`. Did you mean `test_harness`?
133143
30 | | /// ```
134144
| |_______^
135145
|
146+
= help: there is an attribute with a similar name: `test_harness`
136147
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
137148

138-
error: unknown attribute `tesT_harness`. Did you mean `test_harness`?
149+
error: unknown attribute `tesT_harness`
139150
--> $DIR/check-attr-test.rs:26:1
140151
|
141152
26 | / /// b
@@ -145,6 +156,7 @@ error: unknown attribute `tesT_harness`. Did you mean `test_harness`?
145156
30 | | /// ```
146157
| |_______^
147158
|
159+
= help: there is an attribute with a similar name: `test_harness`
148160
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
149161

150162
error: aborting due to 12 previous errors

‎tests/rustdoc-ui/lints/check-attr.stderr

+27-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
1+
error: unknown attribute `compile-fail`
22
--> $DIR/check-attr.rs:3:1
33
|
44
LL | / /// foo
@@ -10,14 +10,15 @@ LL | | /// boo
1010
LL | | /// ```
1111
| |_______^
1212
|
13+
= help: there is an attribute with a similar name: `compile_fail`
1314
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
1415
note: the lint level is defined here
1516
--> $DIR/check-attr.rs:1:9
1617
|
1718
LL | #![deny(rustdoc::invalid_codeblock_attributes)]
1819
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1920

20-
error: unknown attribute `compilefail`. Did you mean `compile_fail`?
21+
error: unknown attribute `compilefail`
2122
--> $DIR/check-attr.rs:3:1
2223
|
2324
LL | / /// foo
@@ -29,9 +30,10 @@ LL | | /// boo
2930
LL | | /// ```
3031
| |_______^
3132
|
33+
= help: there is an attribute with a similar name: `compile_fail`
3234
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
3335

34-
error: unknown attribute `comPile_fail`. Did you mean `compile_fail`?
36+
error: unknown attribute `comPile_fail`
3537
--> $DIR/check-attr.rs:3:1
3638
|
3739
LL | / /// foo
@@ -43,9 +45,10 @@ LL | | /// boo
4345
LL | | /// ```
4446
| |_______^
4547
|
48+
= help: there is an attribute with a similar name: `compile_fail`
4649
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
4750

48-
error: unknown attribute `should-panic`. Did you mean `should_panic`?
51+
error: unknown attribute `should-panic`
4952
--> $DIR/check-attr.rs:13:1
5053
|
5154
LL | / /// bar
@@ -57,9 +60,10 @@ LL | | /// boo
5760
LL | | /// ```
5861
| |_______^
5962
|
63+
= help: there is an attribute with a similar name: `should_panic`
6064
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
6165

62-
error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
66+
error: unknown attribute `shouldpanic`
6367
--> $DIR/check-attr.rs:13:1
6468
|
6569
LL | / /// bar
@@ -71,9 +75,10 @@ LL | | /// boo
7175
LL | | /// ```
7276
| |_______^
7377
|
78+
= help: there is an attribute with a similar name: `should_panic`
7479
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
7580

76-
error: unknown attribute `sHould_panic`. Did you mean `should_panic`?
81+
error: unknown attribute `sHould_panic`
7782
--> $DIR/check-attr.rs:13:1
7883
|
7984
LL | / /// bar
@@ -85,9 +90,10 @@ LL | | /// boo
8590
LL | | /// ```
8691
| |_______^
8792
|
93+
= help: there is an attribute with a similar name: `should_panic`
8894
= help: the code block will either not be tested if not marked as a rust one or won't fail if it doesn't panic when running
8995

90-
error: unknown attribute `no-run`. Did you mean `no_run`?
96+
error: unknown attribute `no-run`
9197
--> $DIR/check-attr.rs:23:1
9298
|
9399
LL | / /// foobar
@@ -99,9 +105,10 @@ LL | | /// boo
99105
LL | | /// ```
100106
| |_______^
101107
|
108+
= help: there is an attribute with a similar name: `no_run`
102109
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
103110

104-
error: unknown attribute `norun`. Did you mean `no_run`?
111+
error: unknown attribute `norun`
105112
--> $DIR/check-attr.rs:23:1
106113
|
107114
LL | / /// foobar
@@ -113,9 +120,10 @@ LL | | /// boo
113120
LL | | /// ```
114121
| |_______^
115122
|
123+
= help: there is an attribute with a similar name: `no_run`
116124
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
117125

118-
error: unknown attribute `no_Run`. Did you mean `no_run`?
126+
error: unknown attribute `no_Run`
119127
--> $DIR/check-attr.rs:23:1
120128
|
121129
LL | / /// foobar
@@ -127,9 +135,10 @@ LL | | /// boo
127135
LL | | /// ```
128136
| |_______^
129137
|
138+
= help: there is an attribute with a similar name: `no_run`
130139
= help: the code block will either not be tested if not marked as a rust one or will be run (which you might not want)
131140

132-
error: unknown attribute `test-harness`. Did you mean `test_harness`?
141+
error: unknown attribute `test-harness`
133142
--> $DIR/check-attr.rs:33:1
134143
|
135144
LL | / /// b
@@ -141,9 +150,10 @@ LL | | /// boo
141150
LL | | /// ```
142151
| |_______^
143152
|
153+
= help: there is an attribute with a similar name: `test_harness`
144154
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
145155

146-
error: unknown attribute `testharness`. Did you mean `test_harness`?
156+
error: unknown attribute `testharness`
147157
--> $DIR/check-attr.rs:33:1
148158
|
149159
LL | / /// b
@@ -155,9 +165,10 @@ LL | | /// boo
155165
LL | | /// ```
156166
| |_______^
157167
|
168+
= help: there is an attribute with a similar name: `test_harness`
158169
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
159170

160-
error: unknown attribute `teSt_harness`. Did you mean `test_harness`?
171+
error: unknown attribute `teSt_harness`
161172
--> $DIR/check-attr.rs:33:1
162173
|
163174
LL | / /// b
@@ -169,9 +180,10 @@ LL | | /// boo
169180
LL | | /// ```
170181
| |_______^
171182
|
183+
= help: there is an attribute with a similar name: `test_harness`
172184
= help: the code block will either not be tested if not marked as a rust one or the code will be wrapped inside a main function
173185

174-
error: unknown attribute `rust2018`. Did you mean `edition2018`?
186+
error: unknown attribute `rust2018`
175187
--> $DIR/check-attr.rs:43:1
176188
|
177189
LL | / /// b
@@ -181,6 +193,8 @@ LL | | /// ```rust2018
181193
LL | | /// boo
182194
LL | | /// ```
183195
| |_______^
196+
|
197+
= help: there is an attribute with a similar name: `edition2018`
184198

185199
error: aborting due to 13 previous errors
186200

There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.