make it more clear what comments refer to; avoid dangling unaligned references
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
This commit is contained in:
parent
b9c9b3e7a2
commit
df227f78c6
@ -17,15 +17,21 @@ struct S {
|
||||
}
|
||||
|
||||
const NEWTYPE: () = unsafe {
|
||||
let buf = [0i32; 4];
|
||||
let x: &Newtype = &*(&buf as *const _ as *const Newtype);
|
||||
|
||||
// Projecting to the newtype works, because it is always at offset 0.
|
||||
let x: &Newtype = unsafe { &*(1usize as *const Newtype) };
|
||||
let field = &x.0;
|
||||
};
|
||||
|
||||
const OFFSET: () = unsafe {
|
||||
// This needs to compute the field offset, but we don't know the type's alignment, so this fail.
|
||||
let x: &S = unsafe { &*(1usize as *const S) };
|
||||
let field = &x.a; //~ERROR: evaluation of constant value failed
|
||||
let buf = [0i32; 4];
|
||||
let x: &S = &*(&buf as *const _ as *const S);
|
||||
|
||||
// This needs to compute the field offset, but we don't know the type's alignment, so this
|
||||
// fails.
|
||||
let field = &x.a;
|
||||
//~^ ERROR: evaluation of constant value failed
|
||||
//~| does not have a known offset
|
||||
};
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
error[E0080]: evaluation of constant value failed
|
||||
--> $DIR/issue-91827-extern-types-field-offset.rs:28:17
|
||||
--> $DIR/issue-91827-extern-types-field-offset.rs:33:17
|
||||
|
|
||||
LL | let field = &x.a;
|
||||
| ^^^^ `extern type` does not have a known offset
|
||||
|
Loading…
x
Reference in New Issue
Block a user