Skip to content

Commit e7fed14

Browse files
committed
explain why REF_AS_USIZE is important
1 parent cf57409 commit e7fed14

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/test/ui/consts/const-eval/ub-ref.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
1111
const NULL: &u16 = unsafe { mem::transmute(0usize) };
1212
//~^ ERROR it is undefined behavior to use this value
1313

14+
// It is very important that we reject this: We do promote `&(4 * REF_AS_USIZE)`,
15+
// but that would fail to compile; so we ended up breaking user code that would
16+
// have worked fine had we not promoted.
1417
const REF_AS_USIZE: usize = unsafe { mem::transmute(&0) };
1518
//~^ ERROR it is undefined behavior to use this value
1619

0 commit comments

Comments
 (0)