Skip to content

Commit

Permalink
explain why REF_AS_USIZE is important
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 30, 2019
1 parent cf57409 commit e7fed14
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/test/ui/consts/const-eval/ub-ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ const UNALIGNED: &u16 = unsafe { mem::transmute(&[0u8; 4]) };
const NULL: &u16 = unsafe { mem::transmute(0usize) };
//~^ ERROR it is undefined behavior to use this value

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

Expand Down

0 comments on commit e7fed14

Please sign in to comment.