about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume.gomez@huawei.com>2024-09-28 01:32:09 +0200
committerGuillaume Gomez <guillaume.gomez@huawei.com>2024-09-28 18:38:11 +0200
commit632fed891df4850e579b2c796de7e18b53d80daa (patch)
treea81cb476befe305948f30c7de8cce8726b035fbc /src
parent84d41e2fc19570e553dc6704e747062373ce4270 (diff)
downloadrust-632fed891df4850e579b2c796de7e18b53d80daa.tar.gz
rust-632fed891df4850e579b2c796de7e18b53d80daa.zip
Improve mistyped docblock attribute warning messages
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/markdown.rs58
1 files changed, 27 insertions, 31 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs
index c487138152d..e1a8dc6e50c 100644
--- a/src/librustdoc/html/markdown.rs
+++ b/src/librustdoc/html/markdown.rs
@@ -1298,37 +1298,31 @@ impl LangString {
                     }
                     LangStringToken::LangToken(x) if extra.is_some() => {
                         let s = x.to_lowercase();
-                        if let Some((flag, help)) = match s.as_str() {
-                            "compile-fail" | "compile_fail" | "compilefail" => Some((
-                                "compile_fail",
-                                "the code block will either not be tested if not marked as a rust \
-                                 one or won't fail if it compiles successfully",
-                            )),
-                            "should-panic" | "should_panic" | "shouldpanic" => Some((
-                                "should_panic",
-                                "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((
-                                "no_run",
-                                "the code block will either not be tested if not marked as a rust \
-                                 one or will be run (which you might not want)",
-                            )),
-                            "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",
-                            )),
+                        if let Some(help) = match s.as_str() {
+                            "compile-fail" | "compile_fail" | "compilefail" => Some(
+                                "use `compile_fail` to invert the results of this test, so that it \
+                                passes if it cannot be compiled and fails if it can",
+                            ),
+                            "should-panic" | "should_panic" | "shouldpanic" => Some(
+                                "use `should_panic` to invert the results of this test, so that if \
+                                passes if it panics and fails if it does not",
+                            ),
+                            "no-run" | "no_run" | "norun" => Some(
+                                "use `no_run` to compile, but not run, the code sample during \
+                                testing",
+                            ),
+                            "test-harness" | "test_harness" | "testharness" => Some(
+                                "use `test_harness` to run functions marked `#[test]` instead of a \
+                                potentially-implicit `main` function",
+                            ),
                             "standalone" | "standalone_crate" => {
                                 if let Some(extra) = extra
                                     && extra.sp.at_least_rust_2024()
                                 {
-                                    Some((
-                                        "standalone-crate",
-                                        "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",
-                                    ))
+                                    Some(
+                                        "use `standalone-crate` to compile this code block \
+                                        separately",
+                                    )
                                 } else {
                                     None
                                 }
@@ -1339,10 +1333,12 @@ impl LangString {
                                 extra.error_invalid_codeblock_attr_with_help(
                                     format!("unknown attribute `{x}`"),
                                     |lint| {
-                                        lint.help(format!(
-                                            "there is an attribute with a similar name: `{flag}`"
-                                        ))
-                                        .help(help);
+                                        lint.help(help).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`",
+                                        );
                                     },
                                 );
                             }