Repository navigation
rustc panics when doctest cannot compile #48394
Description
Activity
- addedT-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.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on Feb 21, 2018 So, after some investigation, i can say that this is basically intentional. First off, yes, there is a literal
panic!()statement in the part of rustdoc that runs the tests:Lines 283 to 297 in b1f8e6f
match (compile_result, compile_fail) { (Ok(()), true) => { panic!("test compiled while it wasn't supposed to") } (Ok(()), false) => {} (Err(()), true) => { if error_codes.len() > 0 { let out = String::from_utf8(data.lock().unwrap().to_vec()).unwrap(); error_codes.retain(|err| !out.contains(err)); } } (Err(()), false) => { panic!("couldn't compile the test") } } ...But as far as i can tell, this is basically the only way to signal to the test handler that the test failed. The tests that run through rustdoc act the same way as regular unit tests, which show a similar panic message:
#[cfg(test)] #[test] fn bar() { panic!("the disco"); }
$ rustc +nightly --test e.rs $ ./e running 1 test test bar ... FAILED failures: ---- bar stdout ---- thread 'bar' panicked at 'the disco', e.rs:10:12 note: Run with `RUST_BACKTRACE=1` for a backtrace. failures: bar test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
...only here, the panic originates in user code, not rustdoc. With exactly the same code as your demo (just the word "no"), it completely fails to compile, but rustdoc doesn't have that luxury - it needs to compile as part of the test. Maybe with the proposed work on the testing system, this can get nicer, but for now can be considered intentional.
Thanks for the report!
I'm not sure if this is really a bug or not, but in
CONTRIBUTING.mdthere isso I might as well open this issue.
Basically, my MCVE is the following: run
cargo init hello, and inlib.rs, and add the following:So, this doc comment should not compile, but when I run
cargo test, I get (among other things) the following:If I understood things well, I think
rustcshould never panics (but I could be wrong) and that's why I opened this issue.