From b3a00234d41938f5ba5dc8a4c80a3a00085665ae Mon Sep 17 00:00:00 2001 From: CAD97 Date: Fri, 29 Apr 2022 23:18:34 -0500 Subject: [PATCH 1/3] add no_compile doctest attribute --- src/librustdoc/html/markdown.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 8877f628332c9..fec12df94da52 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -745,7 +745,7 @@ pub(crate) fn find_testable_code( } CodeBlockKind::Indented => Default::default(), }; - if !block_info.rust { + if !block_info.rust || block_info.no_compile { continue; } @@ -843,6 +843,7 @@ pub(crate) struct LangString { pub(crate) rust: bool, pub(crate) test_harness: bool, pub(crate) compile_fail: bool, + pub(crate) no_compile: bool, pub(crate) error_codes: Vec, pub(crate) edition: Option, } @@ -864,6 +865,7 @@ impl Default for LangString { rust: true, test_harness: false, compile_fail: false, + no_compile: false, error_codes: Vec::new(), edition: None, } @@ -932,6 +934,10 @@ impl LangString { data.ignore = Ignore::All; seen_rust_tags = !seen_other_tags; } + "no_compile" => { + data.no_compile = true; + seen_rust_tags = !seen_other_tags; + } x if x.starts_with("ignore-") => { if enable_per_target_ignores { ignores.push(x.trim_start_matches("ignore-").to_owned()); From 512e95248adc0c8cc0ea0b7aa50d5bd1ccc5f376 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sat, 30 Apr 2022 10:06:19 -0500 Subject: [PATCH 2/3] Add rustdoctest no_compile test --- src/test/rustdoc-ui/no_compile.rs | 25 +++++++++++++++++++++++++ src/test/rustdoc-ui/no_compile.stdout | 6 ++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/rustdoc-ui/no_compile.rs create mode 100644 src/test/rustdoc-ui/no_compile.stdout diff --git a/src/test/rustdoc-ui/no_compile.rs b/src/test/rustdoc-ui/no_compile.rs new file mode 100644 index 0000000000000..dbc6800493eed --- /dev/null +++ b/src/test/rustdoc-ui/no_compile.rs @@ -0,0 +1,25 @@ +// check-pass + +// compile-flags:--test --test-args=--include-ignored --test-args=--test-threads=1 +// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR" +// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME" + +/// These code blocks should be treated as rust code in documentation, but never +/// treated as a test and compiled, even when testing ignored tests. +/// +/// ```rust,no_compile +/// // haha rustc +/// i"have" 0utsmarted k#thee +/// ``` +/// +/// ```no_compile +/// // haha rustc +/// i"have" 0utsmarted k#thee +/// ``` +/// +/// For comparison, ignore does get run: +/// +/// ```ignore +/// println!("Hello, world"); +/// ``` +struct S; diff --git a/src/test/rustdoc-ui/no_compile.stdout b/src/test/rustdoc-ui/no_compile.stdout new file mode 100644 index 0000000000000..7816a9294c699 --- /dev/null +++ b/src/test/rustdoc-ui/no_compile.stdout @@ -0,0 +1,6 @@ + +running 1 test +test $DIR/no_compile.rs - S (line 22) ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME + From 9b7bba6066da40a3ed9d48801b001f1d52bf9a94 Mon Sep 17 00:00:00 2001 From: CAD97 Date: Sat, 30 Apr 2022 10:21:06 -0500 Subject: [PATCH 3/3] Explain rustdoctest ignore in no_compile test --- src/test/rustdoc-ui/no_compile.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-ui/no_compile.rs b/src/test/rustdoc-ui/no_compile.rs index dbc6800493eed..515f52faa3627 100644 --- a/src/test/rustdoc-ui/no_compile.rs +++ b/src/test/rustdoc-ui/no_compile.rs @@ -19,7 +19,7 @@ /// /// For comparison, ignore does get run: /// -/// ```ignore +/// ```ignore (but-actually-we-include-ignored) /// println!("Hello, world"); /// ``` struct S;