2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -17,15 +17,21 @@ struct S {
17
17
}
18
18
19
19
const NEWTYPE : ( ) = unsafe {
20
+ let buf = [ 0i32 ; 4 ] ;
21
+ let x: & Newtype = & * ( & buf as * const _ as * const Newtype ) ;
22
+
20
23
// Projecting to the newtype works, because it is always at offset 0.
21
- let x: & Newtype = unsafe { & * ( 1usize as * const Newtype ) } ;
22
24
let field = & x. 0 ;
23
25
} ;
24
26
25
27
const OFFSET : ( ) = unsafe {
26
- // This needs to compute the field offset, but we don't know the type's alignment, so this fail.
27
- let x: & S = unsafe { & * ( 1usize as * const S ) } ;
28
- let field = & x. a ; //~ERROR: evaluation of constant value failed
28
+ let buf = [ 0i32 ; 4 ] ;
29
+ let x: & S = & * ( & buf as * const _ as * const S ) ;
30
+
31
+ // This needs to compute the field offset, but we don't know the type's alignment, so this
32
+ // fails.
33
+ let field = & x. a ;
34
+ //~^ ERROR: evaluation of constant value failed
29
35
//~| does not have a known offset
30
36
} ;
31
37
Original file line number Diff line number Diff line change 1
1
error[E0080]: evaluation of constant value failed
2
- --> $DIR/issue-91827-extern-types-field-offset.rs:28 :17
2
+ --> $DIR/issue-91827-extern-types-field-offset.rs:33 :17
3
3
|
4
4
LL | let field = &x.a;
5
5
| ^^^^ `extern type` does not have a known offset
0 commit comments