Skip to content

Commit df227f7

Browse files
make it more clear what comments refer to; avoid dangling unaligned references
Co-authored-by: Waffle Maybe <waffle.lapkin@gmail.com>
1 parent b9c9b3e commit df227f7

2 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎tests/ui/consts/const-eval/issue-91827-extern-types-field-offset.rs‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,21 @@ struct S {
1717
}
1818

1919
constNEWTYPE:() = unsafe{
20+
let buf = [0i32;4];
21+
let x:&Newtype = &*(&buf as*const_as*constNewtype);
22+
2023
// Projecting to the newtype works, because it is always at offset 0.
21-
let x:&Newtype = unsafe{&*(1usizeas*constNewtype)};
2224
let field = &x.0;
2325
};
2426

2527
constOFFSET:() = 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{&*(1usizeas*constS)};
28-
let field = &x.a;//~ERROR: evaluation of constant value failed
28+
let buf = [0i32;4];
29+
let x:&S = &*(&buf as*const_as*constS);
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
2935
//~| does not have a known offset
3036
};
3137

‎tests/ui/consts/const-eval/issue-91827-extern-types-field-offset.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
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
33
|
44
LL | let field = &x.a;
55
| ^^^^ `extern type` does not have a known offset

0 commit comments

Comments
 (0)