Skip to content

Commit

Permalink
Follow guidelines for lint suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 12, 2023
1 parent 98aa20b commit bb0fd66
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 36 deletions.
30 changes: 21 additions & 9 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
//! ```

use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_errors::{DiagnosticBuilder, DiagnosticMessage};
use rustc_hir::def_id::DefId;
use rustc_middle::ty::TyCtxt;
pub(crate) use rustc_resolve::rustdoc::main_body_opts;
Expand Down Expand Up @@ -843,15 +843,17 @@ impl<'tcx> ExtraInfo<'tcx> {
fn error_invalid_codeblock_attr_with_help(
&self,
msg: impl Into<DiagnosticMessage>,
help: impl Into<SubdiagnosticMessage>,
f: impl for<'a, 'b> FnOnce(
&'b mut DiagnosticBuilder<'a, ()>,
) -> &'b mut DiagnosticBuilder<'a, ()>,
) {
if let Some(def_id) = self.def_id.as_local() {
self.tcx.struct_span_lint_hir(
crate::lint::INVALID_CODEBLOCK_ATTRIBUTES,
self.tcx.local_def_id_to_hir_id(def_id),
self.sp,
msg,
|lint| lint.help(help),
f,
);
}
}
Expand Down Expand Up @@ -1288,10 +1290,15 @@ impl LangString {
if x.starts_with("rust") && x[4..].parse::<Edition>().is_ok() =>
{
if let Some(extra) = extra {
extra.error_invalid_codeblock_attr(format!(
"unknown attribute `{x}`. Did you mean `edition{}`?",
&x[4..]
));
extra.error_invalid_codeblock_attr_with_help(
format!("unknown attribute `{x}`"),
|lint| {
lint.help(format!(
"there is an attribute with a similar name: `edition{}`",
&x[4..],
))
},
);
}
}
LangStringToken::LangToken(x)
Expand Down Expand Up @@ -1338,8 +1345,13 @@ impl LangString {
} {
if let Some(extra) = extra {
extra.error_invalid_codeblock_attr_with_help(
format!("unknown attribute `{x}`. Did you mean `{flag}`?"),
help,
format!("unknown attribute `{x}`"),
|lint| {
lint.help(format!(
"there is an attribute with a similar name: `{flag}`"
))
.help(help)
},
);
}
}
Expand Down
36 changes: 24 additions & 12 deletions tests/rustdoc-ui/doctest/check-attr-test.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
error: unknown attribute `compile-fail`
--> $DIR/check-attr-test.rs:5:1
|
5 | / /// foo
Expand All @@ -8,14 +8,15 @@ error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
9 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `compile_fail`
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
note: the lint level is defined here
--> $DIR/check-attr-test.rs:3:9
|
3 | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

error: unknown attribute `should-panic`. Did you mean `should_panic`?
error: unknown attribute `should-panic`
--> $DIR/check-attr-test.rs:12:1
|
12 | / /// bar
Expand All @@ -49,9 +52,10 @@ error: unknown attribute `should-panic`. Did you mean `should_panic`?
16 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
error: unknown attribute `shouldpanic`
--> $DIR/check-attr-test.rs:12:1
|
12 | / /// bar
Expand All @@ -61,9 +65,10 @@ error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
16 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `shOuld_panic`. Did you mean `should_panic`?
error: unknown attribute `shOuld_panic`
--> $DIR/check-attr-test.rs:12:1
|
12 | / /// bar
Expand All @@ -73,9 +78,10 @@ error: unknown attribute `shOuld_panic`. Did you mean `should_panic`?
16 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `no-run`. Did you mean `no_run`?
error: unknown attribute `no-run`
--> $DIR/check-attr-test.rs:19:1
|
19 | / /// foobar
Expand All @@ -85,9 +91,10 @@ error: unknown attribute `no-run`. Did you mean `no_run`?
23 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `norun`. Did you mean `no_run`?
error: unknown attribute `norun`
--> $DIR/check-attr-test.rs:19:1
|
19 | / /// foobar
Expand All @@ -97,9 +104,10 @@ error: unknown attribute `norun`. Did you mean `no_run`?
23 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `nO_run`. Did you mean `no_run`?
error: unknown attribute `nO_run`
--> $DIR/check-attr-test.rs:19:1
|
19 | / /// foobar
Expand All @@ -109,9 +117,10 @@ error: unknown attribute `nO_run`. Did you mean `no_run`?
23 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `test-harness`. Did you mean `test_harness`?
error: unknown attribute `test-harness`
--> $DIR/check-attr-test.rs:26:1
|
26 | / /// b
Expand All @@ -121,9 +130,10 @@ error: unknown attribute `test-harness`. Did you mean `test_harness`?
30 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: unknown attribute `testharness`. Did you mean `test_harness`?
error: unknown attribute `testharness`
--> $DIR/check-attr-test.rs:26:1
|
26 | / /// b
Expand All @@ -133,9 +143,10 @@ error: unknown attribute `testharness`. Did you mean `test_harness`?
30 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: unknown attribute `tesT_harness`. Did you mean `test_harness`?
error: unknown attribute `tesT_harness`
--> $DIR/check-attr-test.rs:26:1
|
26 | / /// b
Expand All @@ -145,6 +156,7 @@ error: unknown attribute `tesT_harness`. Did you mean `test_harness`?
30 | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: aborting due to 12 previous errors
Expand Down
40 changes: 27 additions & 13 deletions tests/rustdoc-ui/lints/check-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unknown attribute `compile-fail`. Did you mean `compile_fail`?
error: unknown attribute `compile-fail`
--> $DIR/check-attr.rs:3:1
|
LL | / /// foo
Expand All @@ -10,14 +10,15 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `compile_fail`
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully
note: the lint level is defined here
--> $DIR/check-attr.rs:1:9
|
LL | #![deny(rustdoc::invalid_codeblock_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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

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

error: unknown attribute `should-panic`. Did you mean `should_panic`?
error: unknown attribute `should-panic`
--> $DIR/check-attr.rs:13:1
|
LL | / /// bar
Expand All @@ -57,9 +60,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `shouldpanic`. Did you mean `should_panic`?
error: unknown attribute `shouldpanic`
--> $DIR/check-attr.rs:13:1
|
LL | / /// bar
Expand All @@ -71,9 +75,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `sHould_panic`. Did you mean `should_panic`?
error: unknown attribute `sHould_panic`
--> $DIR/check-attr.rs:13:1
|
LL | / /// bar
Expand All @@ -85,9 +90,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `should_panic`
= 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

error: unknown attribute `no-run`. Did you mean `no_run`?
error: unknown attribute `no-run`
--> $DIR/check-attr.rs:23:1
|
LL | / /// foobar
Expand All @@ -99,9 +105,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `norun`. Did you mean `no_run`?
error: unknown attribute `norun`
--> $DIR/check-attr.rs:23:1
|
LL | / /// foobar
Expand All @@ -113,9 +120,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `no_Run`. Did you mean `no_run`?
error: unknown attribute `no_Run`
--> $DIR/check-attr.rs:23:1
|
LL | / /// foobar
Expand All @@ -127,9 +135,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `no_run`
= 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)

error: unknown attribute `test-harness`. Did you mean `test_harness`?
error: unknown attribute `test-harness`
--> $DIR/check-attr.rs:33:1
|
LL | / /// b
Expand All @@ -141,9 +150,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: unknown attribute `testharness`. Did you mean `test_harness`?
error: unknown attribute `testharness`
--> $DIR/check-attr.rs:33:1
|
LL | / /// b
Expand All @@ -155,9 +165,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: unknown attribute `teSt_harness`. Did you mean `test_harness`?
error: unknown attribute `teSt_harness`
--> $DIR/check-attr.rs:33:1
|
LL | / /// b
Expand All @@ -169,9 +180,10 @@ LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `test_harness`
= 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

error: unknown attribute `rust2018`. Did you mean `edition2018`?
error: unknown attribute `rust2018`
--> $DIR/check-attr.rs:43:1
|
LL | / /// b
Expand All @@ -181,6 +193,8 @@ LL | | /// ```rust2018
LL | | /// boo
LL | | /// ```
| |_______^
|
= help: there is an attribute with a similar name: `edition2018`

error: aborting due to 13 previous errors

Loading

0 comments on commit bb0fd66

Please sign in to comment.