Skip to content

Commit

Permalink
fix: return early when has tainted in mir pass
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Sep 13, 2023
1 parent 7e0261e commit ff733ad
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ impl<'tcx> MirPass<'tcx> for ConstProp {

#[instrument(skip(self, tcx), level = "debug")]
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut 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;
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/unsized/issue-115809.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// compile-flags: --emit=link -Zmir-opt-level=2 -Zpolymorphize=on

fn foo<T>() {
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() {}
19 changes: 19 additions & 0 deletions tests/ui/unsized/issue-115809.stderr
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit ff733ad

Please sign in to comment.