[const-prop] Handle MIR Rvalue::Repeat

This commit is contained in:
Wesley Wiser 2019-09-14 09:22:07 -04:00
parent da59656b3b
commit c8f7e18ceb
4 changed files with 46 additions and 2 deletions

View File

@ -436,13 +436,13 @@ fn const_prop(
// if this isn't a supported operation, then return None
match rvalue {
Rvalue::Repeat(..) |
Rvalue::Aggregate(..) |
Rvalue::NullaryOp(NullOp::Box, _) |
Rvalue::Discriminant(..) => return None,
Rvalue::Use(_) |
Rvalue::Len(_) |
Rvalue::Repeat(..) |
Rvalue::Cast(..) |
Rvalue::NullaryOp(..) |
Rvalue::CheckedBinaryOp(..) |

View File

@ -0,0 +1,37 @@
// compile-flags: -O
fn main() {
let x: u32 = [42; 8][2] + 0;
}
// END RUST SOURCE
// START rustc.main.ConstProp.before.mir
// bb0: {
// ...
// _3 = [const 42u32; 8];
// ...
// _4 = const 2usize;
// _5 = const 8usize;
// _6 = Lt(_4, _5);
// assert(move _6, "index out of bounds: the len is move _5 but the index is _4") -> bb1;
// }
// bb1: {
// _2 = _3[_4];
// _1 = Add(move _2, const 0u32);
// ...
// return;
// }
// END rustc.main.ConstProp.before.mir
// START rustc.main.ConstProp.after.mir
// bb0: {
// ...
// _6 = const true;
// assert(const true, "index out of bounds: the len is move _5 but the index is _4") -> bb1;
// }
// bb1: {
// _2 = const 42u32;
// _1 = Add(move _2, const 0u32);
// ...
// return;
// }
// END rustc.main.ConstProp.after.mir

View File

@ -1,3 +1,4 @@
fn main() {
[0; 3][3u64 as usize]; //~ ERROR the len is 3 but the index is 3
//~| ERROR this expression will panic at runtime
}

View File

@ -6,5 +6,11 @@ LL | [0; 3][3u64 as usize];
|
= note: `#[deny(const_err)]` on by default
error: aborting due to previous error
error: this expression will panic at runtime
--> $DIR/const-prop-ice.rs:2:5
|
LL | [0; 3][3u64 as usize];
| ^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the len is 3 but the index is 3
error: aborting due to 2 previous errors