-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for array lengths that aren't actually
usize
- Loading branch information
Showing
3 changed files
with
48 additions
and
7 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
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,15 @@ | ||
//@ check-fail | ||
//@ compile-flags: -C opt-level=0 | ||
|
||
#![crate_type = "lib"] | ||
|
||
// This used to fail in the known-panics lint, as the MIR was ill-typed due to | ||
// the length constant not actually having type usize. | ||
// https://github.com/rust-lang/rust/issues/134352 | ||
|
||
pub struct BadStruct<const N: i64>(pub [u8; N]); | ||
//~^ ERROR: the constant `N` is not of type `usize` | ||
|
||
pub fn bad_array_length_type(value: BadStruct<3>) -> u8 { | ||
value.0[0] | ||
} |
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 @@ | ||
error: the constant `N` is not of type `usize` | ||
--> $DIR/index_array_bad_type.rs:10:40 | ||
| | ||
LL | pub struct BadStruct<const N: i64>(pub [u8; N]); | ||
| ^^^^^^^ expected `usize`, found `i64` | ||
|
||
error: aborting due to 1 previous error | ||
|