about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2024-02-09 00:40:43 +0000
committerMichael Goulet <michael@errs.io>2024-02-09 00:40:43 +0000
commite32c1ddc5274636c03697f180224f4fa6721f200 (patch)
treeda32a981adee438d24e24e2b39dd1db64cc083c8
parent698a3c7adeed1213e1c3af73158566a85795a3c2 (diff)
downloadrust-e32c1ddc5274636c03697f180224f4fa6721f200.tar.gz
rust-e32c1ddc5274636c03697f180224f4fa6721f200.zip
Don't ice in validation when error body is created
-rw-r--r--compiler/rustc_const_eval/src/transform/validate.rs2
-rw-r--r--tests/ui/mir/validate/error-body.rs9
-rw-r--r--tests/ui/mir/validate/error-body.stderr9
3 files changed, 20 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs
index c4542aaa7b2..3b7b502d3d0 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 00000000000..5b2fbb0b046
--- /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 00000000000..1dfeaf0b7e2
--- /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`.