Rollup merge of #51308 - fanzier:const-prop-array-bounds-check, r=oli-obk
Check array indices in constant propagation Previously, uses of constant weren't correctly propagated. This fixes #48920. r? @oli-obk because you suggested it
This commit is contained in:
commit
54cb13d975
10 changed files with 28 additions and 22 deletions
|
|
@ -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`.
|
||||
|
|
@ -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
|
||||
}
|
||||
17
src/test/ui/const-eval/index_out_of_bounds.stderr
Normal file
17
src/test/ui/const-eval/index_out_of_bounds.stderr
Normal file
|
|
@ -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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue