Skip to content

Commit f813ccd

Browse files
committed
also add a Miri test
1 parent edcb7ab commit f813ccd

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#![feature(extern_types)]
2+
3+
extern"C"{
4+
typeOpaque;
5+
}
6+
7+
structNewtype(Opaque);
8+
9+
structS{
10+
i:i32,
11+
j:i32,
12+
a:Newtype,
13+
}
14+
15+
fnmain(){
16+
let buf = [0i32;4];
17+
18+
let x:&Newtype = unsafe{&*(&buf as*const_as*constNewtype)};
19+
// Projecting to the newtype works, because it is always at offset 0.
20+
let _field = &x.0;
21+
22+
let x:&S = unsafe{&*(&buf as*const_as*constS)};
23+
// Accessing sized fields is perfectly fine, even at non-zero offsets.
24+
let _field = &x.i;
25+
let _field = &x.j;
26+
// This needs to compute the field offset, but we don't know the type's alignment,
27+
// so this panics.
28+
let _field = &x.a;//~ERROR: does not have a known offset
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: unsupported operation: `extern type` does not have a known offset
2+
--> $DIR/extern-type-field-offset.rs:LL:CC
3+
|
4+
LL | let _field = &x.a;
5+
| ^^^^ `extern type` does not have a known offset
6+
|
7+
= help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
8+
= note: BACKTRACE:
9+
= note: inside `main` at $DIR/extern-type-field-offset.rs:LL:CC
10+
11+
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)