Skip to content

Commit

Permalink
Rollup merge of #81040 - osa1:fix_80992, r=jyn514
Browse files Browse the repository at this point in the history
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 #80992
  • Loading branch information
m-ou-se authored Jan 16, 2021
2 parents 1368e81 + 0ef5557 commit 9df8dcb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,12 @@ crate fn make_test(
}
}

// Reset errors so that they won't be reported as compiler bugs when dropping the
// handler. Any errors in the tests will be reported when the test file is compiled,
// Note that we still need to cancel the errors above otherwise `DiagnosticBuilder`
// will panic on drop.
sess.span_diagnostic.reset_err_count();

(found_main, found_extern_crate, found_macro)
})
});
Expand Down
11 changes: 11 additions & 0 deletions src/test/rustdoc-ui/issue-80992.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// compile-flags:--test
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"

pub fn test() -> Result<(), ()> {
//! ```compile_fail
//! fn test() -> Result< {}
//! ```
Ok(())
}
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/issue-80992.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/issue-80992.rs - test (line 7) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME

0 comments on commit 9df8dcb

Please sign in to comment.