diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 40a6610c417..d39042ceba9 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -240,16 +240,6 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> { ) -> Option> { let span = source_info.span; match *rvalue { - // No need to overwrite an already evaluated constant - Rvalue::Use(Operand::Constant(box Constant { - literal: Literal::Value { - value: &ty::Const { - val: ConstVal::Value(_), - .. - }, - }, - .. - })) => None, // This branch exists for the sanity type check Rvalue::Use(Operand::Constant(ref c)) => { assert_eq!(c.ty, place_ty); diff --git a/src/test/compile-fail/const-err-early.rs b/src/test/compile-fail/const-err-early.rs index 6caec159d01..f8b20f6ee79 100644 --- a/src/test/compile-fail/const-err-early.rs +++ b/src/test/compile-fail/const-err-early.rs @@ -19,8 +19,8 @@ pub const C: u8 = 200u8 * 4; //~ ERROR const_err //~^ ERROR this constant cannot be used pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR const_err //~^ ERROR this constant cannot be used -pub const E: u8 = [5u8][1]; -//~^ ERROR const_err +pub const E: u8 = [5u8][1]; //~ ERROR const_err +//~| ERROR this constant cannot be used fn main() { let _a = A; diff --git a/src/test/compile-fail/const-err2.rs b/src/test/compile-fail/const-err2.rs index 46b73371e56..9a5cb5a4a83 100644 --- a/src/test/compile-fail/const-err2.rs +++ b/src/test/compile-fail/const-err2.rs @@ -31,6 +31,7 @@ fn main() { let d = 42u8 - (42u8 + 1); //~^ ERROR const_err let _e = [5u8][1]; + //~^ ERROR const_err black_box(a); black_box(b); black_box(c); diff --git a/src/test/compile-fail/const-err3.rs b/src/test/compile-fail/const-err3.rs index 9656af60024..f5e43b57e77 100644 --- a/src/test/compile-fail/const-err3.rs +++ b/src/test/compile-fail/const-err3.rs @@ -23,6 +23,7 @@ fn main() { let d = 42u8 - (42u8 + 1); //~^ ERROR const_err let _e = [5u8][1]; + //~^ ERROR const_err black_box(b); black_box(c); black_box(d); diff --git a/src/test/run-fail/mir_indexing_oob_1.rs b/src/test/run-fail/mir_indexing_oob_1.rs index 41ff466f810..cf342ad94f9 100644 --- a/src/test/run-fail/mir_indexing_oob_1.rs +++ b/src/test/run-fail/mir_indexing_oob_1.rs @@ -12,6 +12,7 @@ const C: [u32; 5] = [0; 5]; +#[allow(const_err)] fn test() -> u32 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_2.rs b/src/test/run-fail/mir_indexing_oob_2.rs index c5c823428bc..3eb94682b20 100644 --- a/src/test/run-fail/mir_indexing_oob_2.rs +++ b/src/test/run-fail/mir_indexing_oob_2.rs @@ -12,6 +12,7 @@ const C: &'static [u8; 5] = b"hello"; +#[allow(const_err)] fn test() -> u8 { C[10] } diff --git a/src/test/run-fail/mir_indexing_oob_3.rs b/src/test/run-fail/mir_indexing_oob_3.rs index 9bc4b0025e5..06bb6d4d287 100644 --- a/src/test/run-fail/mir_indexing_oob_3.rs +++ b/src/test/run-fail/mir_indexing_oob_3.rs @@ -12,6 +12,7 @@ const C: &'static [u8; 5] = b"hello"; +#[allow(const_err)] fn mir() -> u8 { C[10] } diff --git a/src/test/ui/const-eval/index_out_of_bound.stderr b/src/test/ui/const-eval/index_out_of_bound.stderr deleted file mode 100644 index d16231c72b9..00000000000 --- a/src/test/ui/const-eval/index_out_of_bound.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0080]: constant evaluation error - --> $DIR/index_out_of_bound.rs:11:19 - | -LL | static FOO: i32 = [][0]; - | ^^^^^ index out of bounds: the len is 0 but the index is 0 - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0080`. diff --git a/src/test/ui/const-eval/index_out_of_bound.rs b/src/test/ui/const-eval/index_out_of_bounds.rs similarity index 83% rename from src/test/ui/const-eval/index_out_of_bound.rs rename to src/test/ui/const-eval/index_out_of_bounds.rs index e7ffbe81b9a..f3578bcef6e 100644 --- a/src/test/ui/const-eval/index_out_of_bound.rs +++ b/src/test/ui/const-eval/index_out_of_bounds.rs @@ -11,4 +11,7 @@ static FOO: i32 = [][0]; //~^ ERROR E0080 -fn main() {} +fn main() { + let array = [std::env::args().len()]; + array[1]; //~ ERROR index out of bounds +} diff --git a/src/test/ui/const-eval/index_out_of_bounds.stderr b/src/test/ui/const-eval/index_out_of_bounds.stderr new file mode 100644 index 00000000000..96e592dc209 --- /dev/null +++ b/src/test/ui/const-eval/index_out_of_bounds.stderr @@ -0,0 +1,17 @@ +error[E0080]: constant evaluation error + --> $DIR/index_out_of_bounds.rs:11:19 + | +LL | static FOO: i32 = [][0]; + | ^^^^^ index out of bounds: the len is 0 but the index is 0 + +error: index out of bounds: the len is 1 but the index is 1 + --> $DIR/index_out_of_bounds.rs:16:5 + | +LL | array[1]; //~ ERROR index out of bounds + | ^^^^^^^^ + | + = note: #[deny(const_err)] on by default + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0080`.