about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2021-01-16 17:30:10 +0000
committerGitHub <noreply@github.com>2021-01-16 17:30:10 +0000
commit9df8dcbcde0221a62816d28a7c3bb2e0444ccad3 (patch)
treeafd36471ae56dc49b80589487ef4997b95f3c0ce /src
parent1368e81bcb2f5e9ed0188deb46f7a994f225ab4d (diff)
parent0ef55570fb35a79a32bc062c0a441c02952fd65e (diff)
downloadrust-9df8dcbcde0221a62816d28a7c3bb2e0444ccad3.tar.gz
rust-9df8dcbcde0221a62816d28a7c3bb2e0444ccad3.zip
Rollup merge of #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 #80992
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/doctest.rs6
-rw-r--r--src/test/rustdoc-ui/issue-80992.rs11
-rw-r--r--src/test/rustdoc-ui/issue-80992.stdout6
3 files changed, 23 insertions, 0 deletions
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index cf51162cfb5..3de97f2dd2e 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -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)
         })
     });
diff --git a/src/test/rustdoc-ui/issue-80992.rs b/src/test/rustdoc-ui/issue-80992.rs
new file mode 100644
index 00000000000..8983439bb64
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-80992.rs
@@ -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(())
+}
diff --git a/src/test/rustdoc-ui/issue-80992.stdout b/src/test/rustdoc-ui/issue-80992.stdout
new file mode 100644
index 00000000000..1dd19f46827
--- /dev/null
+++ b/src/test/rustdoc-ui/issue-80992.stdout
@@ -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
+