File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
tests/ui/consts/const-eval Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ const fn bool_cast ( ptr : * const bool ) { unsafe {
2+ let _val = * ptr as u32 ; //~ERROR: evaluation of constant value failed
3+ //~^ interpreting an invalid 8-bit value as a bool
4+ } }
5+
6+ const _: ( ) = {
7+ let v = 3_u8 ;
8+ bool_cast ( & v as * const u8 as * const bool ) ;
9+ } ;
10+
11+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error[E0080]: evaluation of constant value failed
2+ --> $DIR/ub-invalid-values.rs:2:16
3+ |
4+ LL | let _val = *ptr as u32;
5+ | ^^^^^^^^^^^ interpreting an invalid 8-bit value as a bool: 0x03
6+ |
7+ note: inside `bool_cast`
8+ --> $DIR/ub-invalid-values.rs:2:16
9+ |
10+ LL | let _val = *ptr as u32;
11+ | ^^^^^^^^^^^
12+ note: inside `_`
13+ --> $DIR/ub-invalid-values.rs:8:5
14+ |
15+ LL | bool_cast(&v as *const u8 as *const bool);
16+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
17+
18+ error: aborting due to 1 previous error
19+
20+ For more information about this error, try `rustc --explain E0080`.
You can’t perform that action at this time.
0 commit comments