) -> Option<Const<'tcx>> {
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);
//~^ 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;
let d = 42u8 - (42u8 + 1);
//~^ ERROR const_err
let _e = [5u8][1];
+ //~^ ERROR const_err
black_box(a);
black_box(b);
black_box(c);
let d = 42u8 - (42u8 + 1);
//~^ ERROR const_err
let _e = [5u8][1];
+ //~^ ERROR const_err
black_box(b);
black_box(c);
black_box(d);
const C: [u32; 5] = [0; 5];
+#[allow(const_err)]
fn test() -> u32 {
C[10]
}
const C: &'static [u8; 5] = b"hello";
+#[allow(const_err)]
fn test() -> u8 {
C[10]
}
const C: &'static [u8; 5] = b"hello";
+#[allow(const_err)]
fn mir() -> u8 {
C[10]
}
+++ /dev/null
-// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-static FOO: i32 = [][0];
-//~^ ERROR E0080
-
-fn main() {}
+++ /dev/null
-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`.
--- /dev/null
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+static FOO: i32 = [][0];
+//~^ ERROR E0080
+
+fn main() {
+ let array = [std::env::args().len()];
+ array[1]; //~ ERROR index out of bounds
+}
--- /dev/null
+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`.