-
Notifications
You must be signed in to change notification settings - Fork 14k
Open
Labels
A-doctestsArea: Documentation tests, run by rustdocArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
Problem
Given a documentation example that does not build (or builds but fails execution), annotated with ```ignore, I expect:
- Running
cargo test --docreports the example as ignored. No failures are reported. => Correct. - Running
cargo test --doc -- --ignoredbuilds (and runs) the sample and reports the build (or execution) errors => Incorrect.
a. The example is reported as built and run.
b. The example is reported as succesful. - (Surprisingly?), running
cargo test --doc -- --ignored --show-outputhas the expected behaviour. => Correct
a . The example is reported as built (or built and run).
b. Build (or execution) failures are reported.
Steps
Given the following src\lib.rs
/// # Example
/// ```ignore
/// let x = UnknownType::new();
/// println!("Doesn't build");
/// ```
pub fn no_build(left: u64, right: u64) -> u64 {
left + right
}
/// # Example
/// ```ignore
/// assert!(false);
/// println!("Builds but fails");
/// ```
pub fn build_no_run(left: u64, right: u64) -> u64 {
left * right
}
/// # Example
/// ```ignore
/// println!("Builds and succeeds");
/// ```
pub fn succeeds(left: u64, right: u64) -> u64 {
left - right
}and Cargo.toml
[package]
name = "bar"
version = "0.1.0"
edition = "2024"
[dependencies]
- Run
cargo test --doc -- --ignored - See (unexpected) output
Doc-tests bar running 3 tests test src\lib.rs - build_no_run (line 11) ... ok test src\lib.rs - no_build (line 2) ... ok test src\lib.rs - succeeds (line 20) ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - Run
cargo test --doc -- --ignored --show-output - See (expected) output
Doc-tests bar running 3 tests test src\lib.rs - no_build (line 2) ... FAILED test src\lib.rs - succeeds (line 20) ... ok test src\lib.rs - build_no_run (line 11) ... FAILED successes: successes: src\lib.rs - succeeds (line 20) failures: ---- src\lib.rs - no_build (line 2) stdout ---- error[E0433]: failed to resolve: use of undeclared type `UnknownType` --> src\lib.rs:3:9 | 3 | let x = UnknownType::new(); | ^^^^^^^^^^^ use of undeclared type `UnknownType` error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0433`. Couldn't compile the test. ---- src\lib.rs - build_no_run (line 11) stdout ---- Test executable failed (exit code: 101). stderr: thread 'main' panicked at src\lib.rs:3:1: assertion failed: false note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace failures: src\lib.rs - build_no_run (line 11) src\lib.rs - no_build (line 2) test result: FAILED. 1 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 6.12s error: doctest failed, to rerun pass `--doc`
Possible Solution(s)
No response
Notes
No response
Version
cargo 1.88.0 (873a06493 2025-05-10)
release: 1.88.0
commit-hash: 873a0649350c486caf67be772828a4f36bb4734c
commit-date: 2025-05-10
host: x86_64-pc-windows-msvc
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.1-DEV (sys:0.4.80+curl-8.12.1 vendored ssl:Schannel)
os: Windows 10.0.22631 (Windows 11 Enterprise) [64-bit]
Metadata
Metadata
Assignees
Labels
A-doctestsArea: Documentation tests, run by rustdocArea: Documentation tests, run by rustdocC-bugCategory: This is a bug.Category: This is a bug.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.Relevant to the rustdoc team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Type
Projects
Status
No status