From 967410c64031002500534863b8d945b9f21bb1c8 Mon Sep 17 00:00:00 2001 From: bohan Date: Fri, 8 Sep 2023 01:39:26 +0800 Subject: [PATCH] fix: return ealry when has tainted in mir-lint --- .../src/const_prop_lint.rs | 4 ++++ tests/ui/unsized/issue-115203.rs | 11 +++++++++++ tests/ui/unsized/issue-115203.stderr | 19 +++++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 tests/ui/unsized/issue-115203.rs create mode 100644 tests/ui/unsized/issue-115203.stderr diff --git a/compiler/rustc_mir_transform/src/const_prop_lint.rs b/compiler/rustc_mir_transform/src/const_prop_lint.rs index 4b51beed09558..b52827a1e88d8 100644 --- a/compiler/rustc_mir_transform/src/const_prop_lint.rs +++ b/compiler/rustc_mir_transform/src/const_prop_lint.rs @@ -39,6 +39,10 @@ pub struct ConstProp; impl<'tcx> MirLint<'tcx> for ConstProp { fn run_lint(&self, tcx: TyCtxt<'tcx>, body: &Body<'tcx>) { + if body.tainted_by_errors.is_some() { + return; + } + // will be evaluated by miri and produce its errors there if body.source.promoted.is_some() { return; diff --git a/tests/ui/unsized/issue-115203.rs b/tests/ui/unsized/issue-115203.rs new file mode 100644 index 0000000000000..5fe7bd64288da --- /dev/null +++ b/tests/ui/unsized/issue-115203.rs @@ -0,0 +1,11 @@ +// compile-flags: --emit link + +fn main() { + 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 + [[]] => (), + _ => (), + } +} diff --git a/tests/ui/unsized/issue-115203.stderr b/tests/ui/unsized/issue-115203.stderr new file mode 100644 index 0000000000000..3ee734988c5a8 --- /dev/null +++ b/tests/ui/unsized/issue-115203.stderr @@ -0,0 +1,19 @@ +error[E0161]: cannot move a value of type `[i32]` + --> $DIR/issue-115203.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-115203.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`.