-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
const_prop_lint: Consider array length constant even if array is not
- Loading branch information
Showing
6 changed files
with
79 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/test/ui/const_prop/issue-98444-const-index-out-of-bounds.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// build-fail | ||
// Need to use build-fail because check doesn't run constant propagation. | ||
|
||
fn main() { | ||
let xs: [i32; 5] = [1, 2, 3, 4, 5]; | ||
let _ = &xs; | ||
let _ = xs[7]; //~ ERROR this operation will panic at runtime | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/const_prop/issue-98444-const-index-out-of-bounds.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: this operation will panic at runtime | ||
--> $DIR/issue-98444-const-index-out-of-bounds.rs:7:13 | ||
| | ||
LL | let _ = xs[7]; | ||
| ^^^^^ index out of bounds: the length is 5 but the index is 7 | ||
| | ||
= note: `#[deny(unconditional_panic)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
// check-pass | ||
#![allow(unconditional_panic)] | ||
|
||
struct Generic<T>(T); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters