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()); diff --git a/src/test/rustdoc-ui/no_compile.rs b/src/test/rustdoc-ui/no_compile.rs new file mode 100644 index 0000000000000..515f52faa3627 --- /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 (but-actually-we-include-ignored) +/// 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 +