Skip to content

add no_compile doctest attribute #96573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ pub(crate) fn find_testable_code<T: doctest::Tester>(
}
CodeBlockKind::Indented => Default::default(),
};
if !block_info.rust {
if !block_info.rust || block_info.no_compile {
continue;
}

Expand Down Expand Up @@ -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<String>,
pub(crate) edition: Option<Edition>,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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());
Expand Down
25 changes: 25 additions & 0 deletions src/test/rustdoc-ui/no_compile.rs
Original file line number Diff line number Diff line change
@@ -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;
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/no_compile.stdout
Original file line number Diff line number Diff line change
@@ -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