rustc_const_eval: track the length and index in IndexOutOfBounds.
This commit is contained in:
parent
afc598e075
commit
1447fbf183
9 changed files with 40 additions and 17 deletions
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
const A: &'static [i32] = &[];
|
||||
const B: i32 = (&A)[1];
|
||||
//~^ ERROR: array index out of bounds
|
||||
//~^ ERROR index out of bounds: the len is 0 but the index is 1
|
||||
|
||||
fn main() {
|
||||
let _ = B;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
const A: [i32; 0] = [];
|
||||
const B: i32 = A[1]; //~ ERROR: array index out of bounds
|
||||
const B: i32 = A[1];
|
||||
//~^ ERROR index out of bounds: the len is 0 but the index is 1
|
||||
|
||||
fn main() {
|
||||
let _ = B;
|
||||
|
|
|
|||
|
|
@ -8,13 +8,15 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// ignore-tidy-linelength
|
||||
|
||||
#![feature(const_indexing)]
|
||||
|
||||
const FOO: [u32; 3] = [1, 2, 3];
|
||||
const BAR: u32 = FOO[5]; // no error, because the error below occurs before regular const eval
|
||||
|
||||
const BLUB: [u32; FOO[4]] = [5, 6];
|
||||
//~^ ERROR array length constant evaluation error: array index out of bounds [E0250]
|
||||
//~^ ERROR array length constant evaluation error: index out of bounds: the len is 3 but the index is 4 [E0250]
|
||||
|
||||
fn main() {
|
||||
let _ = BAR;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,10 @@ pub const A: i8 = -std::i8::MIN; //~ ERROR attempted to negate with overflow
|
|||
pub const B: u8 = 200u8 + 200u8; //~ ERROR attempted to add with overflow
|
||||
pub const C: u8 = 200u8 * 4; //~ ERROR attempted to multiply with overflow
|
||||
pub const D: u8 = 42u8 - (42u8 + 1); //~ ERROR attempted to subtract with overflow
|
||||
pub const E: u8 = [5u8][1]; //~ ERROR index out of bounds
|
||||
pub const E: u8 = [5u8][1];
|
||||
//~^ ERROR index out of bounds: the len is 1 but the index is 1
|
||||
|
||||
fn main() {
|
||||
let _e = [6u8][1]; //~ ERROR: array index out of bounds
|
||||
let _e = [6u8][1];
|
||||
//~^ ERROR index out of bounds: the len is 1 but the index is 1
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ fn black_box<T>(_: T) {
|
|||
|
||||
// Make sure that the two uses get two errors.
|
||||
const FOO: u8 = [5u8][1];
|
||||
//~^ ERROR array index out of bounds
|
||||
//~^^ ERROR array index out of bounds
|
||||
//~^ ERROR index out of bounds: the len is 1 but the index is 1
|
||||
//~^^ ERROR index out of bounds: the len is 1 but the index is 1
|
||||
|
||||
fn main() {
|
||||
let a = -std::i8::MIN;
|
||||
|
|
@ -34,7 +34,7 @@ fn main() {
|
|||
let d = 42u8 - (42u8 + 1);
|
||||
//~^ WARN attempted to subtract with overflow
|
||||
let _e = [5u8][1];
|
||||
//~^ WARN array index out of bounds
|
||||
//~^ WARN index out of bounds: the len is 1 but the index is 1
|
||||
black_box(a);
|
||||
black_box(b);
|
||||
black_box(c);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@
|
|||
// except according to those terms.
|
||||
|
||||
const FOO: &'static[u32] = &[1, 2, 3];
|
||||
const BAR: u32 = FOO[5]; //~ ERROR array index out of bounds
|
||||
const BAR: u32 = FOO[5];
|
||||
//~^ ERROR index out of bounds: the len is 3 but the index is 5
|
||||
|
||||
fn main() {
|
||||
let _ = BAR;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue