From e32c1ddc5274636c03697f180224f4fa6721f200 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 9 Feb 2024 00:40:43 +0000 Subject: [PATCH] Don't ice in validation when error body is created --- compiler/rustc_const_eval/src/transform/validate.rs | 2 ++ tests/ui/mir/validate/error-body.rs | 9 +++++++++ tests/ui/mir/validate/error-body.stderr | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/ui/mir/validate/error-body.rs create mode 100644 tests/ui/mir/validate/error-body.stderr diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index c4542aaa7b2fb..3b7b502d3d08a 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -60,6 +60,8 @@ impl<'tcx> MirPass<'tcx> for Validator { ty::Closure(..) => Abi::RustCall, ty::CoroutineClosure(..) => Abi::RustCall, ty::Coroutine(..) => Abi::Rust, + // No need to do MIR validation on error bodies + ty::Error(_) => return, _ => { span_bug!(body.span, "unexpected body ty: {:?} phase {:?}", body_ty, mir_phase) } diff --git a/tests/ui/mir/validate/error-body.rs b/tests/ui/mir/validate/error-body.rs new file mode 100644 index 0000000000000..5b2fbb0b04699 --- /dev/null +++ b/tests/ui/mir/validate/error-body.rs @@ -0,0 +1,9 @@ +// compile-flags: -Zvalidate-mir + +fn _test() { + let x = || 45; + missing(); + //~^ ERROR cannot find function `missing` in this scope +} + +fn main() {} diff --git a/tests/ui/mir/validate/error-body.stderr b/tests/ui/mir/validate/error-body.stderr new file mode 100644 index 0000000000000..1dfeaf0b7e2cb --- /dev/null +++ b/tests/ui/mir/validate/error-body.stderr @@ -0,0 +1,9 @@ +error[E0425]: cannot find function `missing` in this scope + --> $DIR/error-body.rs:5:5 + | +LL | missing(); + | ^^^^^^^ not found in this scope + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0425`.