From 6a25bfa08c39e6c6225d3e19b4e97cc39e5dd0f6 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sun, 27 Nov 2022 17:58:28 -0500 Subject: [PATCH] Don't silently ignore errors that happen during rendering This caught a real, existing bug. --- src/librustdoc/lib.rs | 2 +- .../{rustdoc => rustdoc-ui}/const-evalutation-ice.rs | 1 + src/test/rustdoc-ui/const-evalutation-ice.stderr | 9 +++++++++ 3 files changed, 11 insertions(+), 1 deletion(-) rename src/test/{rustdoc => rustdoc-ui}/const-evalutation-ice.rs (79%) create mode 100644 src/test/rustdoc-ui/const-evalutation-ice.stderr diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1a84ec650474d..faca88d71c581 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -689,7 +689,7 @@ fn run_renderer<'tcx, T: formats::FormatRenderer<'tcx>>( tcx: TyCtxt<'tcx>, ) -> MainResult { match formats::run_format::(krate, renderopts, cache, tcx) { - Ok(_) => Ok(()), + Ok(_) => tcx.sess.has_errors().map_or(Ok(()), Err), Err(e) => { let mut msg = tcx.sess.struct_err(&format!("couldn't generate documentation: {}", e.error)); diff --git a/src/test/rustdoc/const-evalutation-ice.rs b/src/test/rustdoc-ui/const-evalutation-ice.rs similarity index 79% rename from src/test/rustdoc/const-evalutation-ice.rs rename to src/test/rustdoc-ui/const-evalutation-ice.rs index 68c7f9c5686ff..96231ba56498f 100644 --- a/src/test/rustdoc/const-evalutation-ice.rs +++ b/src/test/rustdoc-ui/const-evalutation-ice.rs @@ -8,3 +8,4 @@ pub struct S { } pub const N: usize = 0 - (mem::size_of::() != 4) as usize; +//~^ ERROR evaluation of constant value failed diff --git a/src/test/rustdoc-ui/const-evalutation-ice.stderr b/src/test/rustdoc-ui/const-evalutation-ice.stderr new file mode 100644 index 0000000000000..8392d49089602 --- /dev/null +++ b/src/test/rustdoc-ui/const-evalutation-ice.stderr @@ -0,0 +1,9 @@ +error[E0080]: evaluation of constant value failed + --> $DIR/const-evalutation-ice.rs:10:22 + | +LL | pub const N: usize = 0 - (mem::size_of::() != 4) as usize; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ attempt to compute `0_usize - 1_usize`, which would overflow + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`.