From 7c53e87d556f7ce878a446c9db058877ceb69d10 Mon Sep 17 00:00:00 2001 From: bohan Date: Wed, 13 Sep 2023 22:54:22 +0800 Subject: [PATCH] fix: skip opt if body has tainted error --- compiler/rustc_mir_transform/src/lib.rs | 5 +++++ tests/ui/unsized/issue-115809.rs | 13 +++++++++++++ tests/ui/unsized/issue-115809.stderr | 19 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 tests/ui/unsized/issue-115809.rs create mode 100644 tests/ui/unsized/issue-115809.stderr diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index ff4385e811697..70d4ea74d1a71 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -606,6 +606,11 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, did: LocalDefId) -> Body<'_> { let body = tcx.mir_drops_elaborated_and_const_checked(did).steal(); let mut body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst); debug!("body: {:#?}", body); + + if body.tainted_by_errors.is_some() { + return body; + } + run_optimization_passes(tcx, &mut body); body diff --git a/tests/ui/unsized/issue-115809.rs b/tests/ui/unsized/issue-115809.rs new file mode 100644 index 0000000000000..ff25365ea50c0 --- /dev/null +++ b/tests/ui/unsized/issue-115809.rs @@ -0,0 +1,13 @@ +// compile-flags: --emit=link -Zmir-opt-level=2 -Zpolymorphize=on + +fn foo() { + let a: [i32; 0] = []; + match [a[..]] { + //~^ ERROR cannot move a value of type `[i32] + //~| ERROR cannot move out of type `[i32]`, a non-copy slice + [[x]] => {} + _ => (), + } +} + +fn main() {} diff --git a/tests/ui/unsized/issue-115809.stderr b/tests/ui/unsized/issue-115809.stderr new file mode 100644 index 0000000000000..a92554b79b956 --- /dev/null +++ b/tests/ui/unsized/issue-115809.stderr @@ -0,0 +1,19 @@ +error[E0161]: cannot move a value of type `[i32]` + --> $DIR/issue-115809.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ the size of `[i32]` cannot be statically determined + +error[E0508]: cannot move out of type `[i32]`, a non-copy slice + --> $DIR/issue-115809.rs:5:12 + | +LL | match [a[..]] { + | ^^^^^ + | | + | cannot move out of here + | move occurs because value has type `[i32]`, which does not implement the `Copy` trait + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0161, E0508. +For more information about an error, try `rustc --explain E0161`.