Improve mistyped docblock attribute warning messages

This commit is contained in:
Guillaume Gomez 2024-09-28 01:32:09 +02:00
parent 84d41e2fc1
commit 632fed891d
5 changed files with 85 additions and 89 deletions

View file

@ -1298,37 +1298,31 @@ impl LangString {
} }
LangStringToken::LangToken(x) if extra.is_some() => { LangStringToken::LangToken(x) if extra.is_some() => {
let s = x.to_lowercase(); let s = x.to_lowercase();
if let Some((flag, help)) = match s.as_str() { if let Some(help) = match s.as_str() {
"compile-fail" | "compile_fail" | "compilefail" => Some(( "compile-fail" | "compile_fail" | "compilefail" => Some(
"compile_fail", "use `compile_fail` to invert the results of this test, so that it \
"the code block will either not be tested if not marked as a rust \ passes if it cannot be compiled and fails if it can",
one or won't fail if it compiles successfully", ),
)), "should-panic" | "should_panic" | "shouldpanic" => Some(
"should-panic" | "should_panic" | "shouldpanic" => Some(( "use `should_panic` to invert the results of this test, so that if \
"should_panic", passes if it panics and fails if it does not",
"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", "no-run" | "no_run" | "norun" => Some(
)), "use `no_run` to compile, but not run, the code sample during \
"no-run" | "no_run" | "norun" => Some(( testing",
"no_run", ),
"the code block will either not be tested if not marked as a rust \ "test-harness" | "test_harness" | "testharness" => Some(
one or will be run (which you might not want)", "use `test_harness` to run functions marked `#[test]` instead of a \
)), potentially-implicit `main` function",
"test-harness" | "test_harness" | "testharness" => Some(( ),
"test_harness",
"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",
)),
"standalone" | "standalone_crate" => { "standalone" | "standalone_crate" => {
if let Some(extra) = extra if let Some(extra) = extra
&& extra.sp.at_least_rust_2024() && extra.sp.at_least_rust_2024()
{ {
Some(( Some(
"standalone-crate", "use `standalone-crate` to compile this code block \
"the code block will either not be tested if not marked as \ separately",
a rust one or the code will be run as part of the merged \ )
doctests if compatible",
))
} else { } else {
None None
} }
@ -1339,10 +1333,12 @@ impl LangString {
extra.error_invalid_codeblock_attr_with_help( extra.error_invalid_codeblock_attr_with_help(
format!("unknown attribute `{x}`"), format!("unknown attribute `{x}`"),
|lint| { |lint| {
lint.help(format!( lint.help(help).help(
"there is an attribute with a similar name: `{flag}`" "this code block may be skipped during testing, \
)) because unknown attributes are treated as markers for \
.help(help); code samples written in other programming languages, \
unless it is also explicitly marked as `rust`",
);
}, },
); );
} }

View file

@ -8,8 +8,8 @@ error: unknown attribute `compile-fail`
9 | | /// ``` 9 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
note: the lint level is defined here note: the lint level is defined here
--> $DIR/check-attr-test.rs:3:9 --> $DIR/check-attr-test.rs:3:9
| |
@ -26,8 +26,8 @@ error: unknown attribute `compilefail`
9 | | /// ``` 9 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `comPile_fail` error: unknown attribute `comPile_fail`
--> $DIR/check-attr-test.rs:5:1 --> $DIR/check-attr-test.rs:5:1
@ -39,8 +39,8 @@ error: unknown attribute `comPile_fail`
9 | | /// ``` 9 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `should-panic` error: unknown attribute `should-panic`
--> $DIR/check-attr-test.rs:12:1 --> $DIR/check-attr-test.rs:12:1
@ -52,8 +52,8 @@ error: unknown attribute `should-panic`
16 | | /// ``` 16 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `shouldpanic` error: unknown attribute `shouldpanic`
--> $DIR/check-attr-test.rs:12:1 --> $DIR/check-attr-test.rs:12:1
@ -65,8 +65,8 @@ error: unknown attribute `shouldpanic`
16 | | /// ``` 16 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `shOuld_panic` error: unknown attribute `shOuld_panic`
--> $DIR/check-attr-test.rs:12:1 --> $DIR/check-attr-test.rs:12:1
@ -78,8 +78,8 @@ error: unknown attribute `shOuld_panic`
16 | | /// ``` 16 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `no-run` error: unknown attribute `no-run`
--> $DIR/check-attr-test.rs:19:1 --> $DIR/check-attr-test.rs:19:1
@ -91,8 +91,8 @@ error: unknown attribute `no-run`
23 | | /// ``` 23 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `norun` error: unknown attribute `norun`
--> $DIR/check-attr-test.rs:19:1 --> $DIR/check-attr-test.rs:19:1
@ -104,8 +104,8 @@ error: unknown attribute `norun`
23 | | /// ``` 23 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `nO_run` error: unknown attribute `nO_run`
--> $DIR/check-attr-test.rs:19:1 --> $DIR/check-attr-test.rs:19:1
@ -117,8 +117,8 @@ error: unknown attribute `nO_run`
23 | | /// ``` 23 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `test-harness` error: unknown attribute `test-harness`
--> $DIR/check-attr-test.rs:26:1 --> $DIR/check-attr-test.rs:26:1
@ -130,8 +130,8 @@ error: unknown attribute `test-harness`
30 | | /// ``` 30 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `testharness` error: unknown attribute `testharness`
--> $DIR/check-attr-test.rs:26:1 --> $DIR/check-attr-test.rs:26:1
@ -143,8 +143,8 @@ error: unknown attribute `testharness`
30 | | /// ``` 30 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `tesT_harness` error: unknown attribute `tesT_harness`
--> $DIR/check-attr-test.rs:26:1 --> $DIR/check-attr-test.rs:26:1
@ -156,8 +156,8 @@ error: unknown attribute `tesT_harness`
30 | | /// ``` 30 | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: aborting due to 12 previous errors error: aborting due to 12 previous errors

View file

@ -10,8 +10,8 @@ error: unknown attribute `standalone`
16 | | //! ``` 16 | | //! ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `standalone-crate` = help: use `standalone-crate` to compile this code block separately
= help: the code block will either not be tested if not marked as a rust one or the code will be run as part of the merged doctests if compatible = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
note: the lint level is defined here note: the lint level is defined here
--> $DIR/standalone-warning-2024.rs:8:9 --> $DIR/standalone-warning-2024.rs:8:9
| |
@ -31,8 +31,8 @@ error: unknown attribute `standalone_crate`
16 | | //! ``` 16 | | //! ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `standalone-crate` = help: use `standalone-crate` to compile this code block separately
= help: the code block will either not be tested if not marked as a rust one or the code will be run as part of the merged doctests if compatible = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors

View file

@ -10,8 +10,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
note: the lint level is defined here note: the lint level is defined here
--> $DIR/check-attr.rs:1:9 --> $DIR/check-attr.rs:1:9
| |
@ -30,8 +30,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `comPile_fail` error: unknown attribute `comPile_fail`
--> $DIR/check-attr.rs:3:1 --> $DIR/check-attr.rs:3:1
@ -45,8 +45,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `compile_fail` = help: use `compile_fail` to invert the results of this test, so that it passes if it cannot be compiled and fails if it can
= help: the code block will either not be tested if not marked as a rust one or won't fail if it compiles successfully = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `should-panic` error: unknown attribute `should-panic`
--> $DIR/check-attr.rs:13:1 --> $DIR/check-attr.rs:13:1
@ -60,8 +60,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `shouldpanic` error: unknown attribute `shouldpanic`
--> $DIR/check-attr.rs:13:1 --> $DIR/check-attr.rs:13:1
@ -75,8 +75,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `sHould_panic` error: unknown attribute `sHould_panic`
--> $DIR/check-attr.rs:13:1 --> $DIR/check-attr.rs:13:1
@ -90,8 +90,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `no-run` error: unknown attribute `no-run`
--> $DIR/check-attr.rs:23:1 --> $DIR/check-attr.rs:23:1
@ -105,8 +105,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `norun` error: unknown attribute `norun`
--> $DIR/check-attr.rs:23:1 --> $DIR/check-attr.rs:23:1
@ -120,8 +120,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `no_Run` error: unknown attribute `no_Run`
--> $DIR/check-attr.rs:23:1 --> $DIR/check-attr.rs:23:1
@ -135,8 +135,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `no_run` = help: use `no_run` to compile, but not run, the code sample during testing
= 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) = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `test-harness` error: unknown attribute `test-harness`
--> $DIR/check-attr.rs:33:1 --> $DIR/check-attr.rs:33:1
@ -150,8 +150,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `testharness` error: unknown attribute `testharness`
--> $DIR/check-attr.rs:33:1 --> $DIR/check-attr.rs:33:1
@ -165,8 +165,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `teSt_harness` error: unknown attribute `teSt_harness`
--> $DIR/check-attr.rs:33:1 --> $DIR/check-attr.rs:33:1
@ -180,8 +180,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: unknown attribute `rust2018` error: unknown attribute `rust2018`
--> $DIR/check-attr.rs:43:1 --> $DIR/check-attr.rs:43:1
@ -222,8 +222,8 @@ LL | | /// boo
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `should_panic` = help: use `should_panic` to invert the results of this test, so that if passes if it panics and fails if it does not
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: aborting due to 15 previous errors error: aborting due to 15 previous errors

View file

@ -31,8 +31,8 @@ LL | | //! let x = 12;
LL | | //! ``` LL | | //! ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
note: the lint level is defined here note: the lint level is defined here
--> $DIR/check-fail.rs:6:9 --> $DIR/check-fail.rs:6:9
| |
@ -51,8 +51,8 @@ LL | | /// let x = 12;
LL | | /// ``` LL | | /// ```
| |_______^ | |_______^
| |
= help: there is an attribute with a similar name: `test_harness` = help: use `test_harness` to run functions marked `#[test]` instead of a potentially-implicit `main` function
= 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 = help: this code block may be skipped during testing, because unknown attributes are treated as markers for code samples written in other programming languages, unless it is also explicitly marked as `rust`
error: aborting due to 4 previous errors error: aborting due to 4 previous errors