Skip to content

Commit 6a131cb

Browse files
authored
Rollup merge of rust-lang#81040 - osa1:fix_80992, r=jyn514
doctest: Reset errors before dropping the parse session The first parse is to collect whether the code contains macros, has `main`, and uses other crates. In that pass we ignore errors as those will be reported when the test file is actually built. For that we need to reset errors in the `Diagnostic` otherwise when dropping it unhandled errors will be reported as compiler bugs. Fixes rust-lang#80992
2 parents 58c1b90 + 0ef5557 commit 6a131cb

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/librustdoc/doctest.rs

+6
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,12 @@ crate fn make_test(
500500
}
501501
}
502502

503+
// Reset errors so that they won't be reported as compiler bugs when dropping the
504+
// handler. Any errors in the tests will be reported when the test file is compiled,
505+
// Note that we still need to cancel the errors above otherwise `DiagnosticBuilder`
506+
// will panic on drop.
507+
sess.span_diagnostic.reset_err_count();
508+
503509
(found_main, found_extern_crate, found_macro)
504510
})
505511
});

src/test/rustdoc-ui/issue-80992.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// check-pass
2+
// compile-flags:--test
3+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
4+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
5+
6+
pub fn test() -> Result<(), ()> {
7+
//! ```compile_fail
8+
//! fn test() -> Result< {}
9+
//! ```
10+
Ok(())
11+
}
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
running 1 test
3+
test $DIR/issue-80992.rs - test (line 7) ... ok
4+
5+
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
6+

0 commit comments

Comments
 (0)