-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add const eval bool-to-int cast test
- Loading branch information
Showing
2 changed files
with
31 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const fn bool_cast(ptr: *const bool) { unsafe { | ||
let _val = *ptr as u32; //~ERROR: evaluation of constant value failed | ||
//~^ interpreting an invalid 8-bit value as a bool | ||
}} | ||
|
||
const _: () = { | ||
let v = 3_u8; | ||
bool_cast(&v as *const u8 as *const bool); | ||
}; | ||
|
||
fn main() {} |
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,20 @@ | ||
error[E0080]: evaluation of constant value failed | ||
--> $DIR/ub-invalid-values.rs:2:16 | ||
| | ||
LL | let _val = *ptr as u32; | ||
| ^^^^^^^^^^^ interpreting an invalid 8-bit value as a bool: 0x03 | ||
| | ||
note: inside `bool_cast` | ||
--> $DIR/ub-invalid-values.rs:2:16 | ||
| | ||
LL | let _val = *ptr as u32; | ||
| ^^^^^^^^^^^ | ||
note: inside `_` | ||
--> $DIR/ub-invalid-values.rs:8:5 | ||
| | ||
LL | bool_cast(&v as *const u8 as *const bool); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0080`. |