rust/tests/ui/offset-of/offset-of-dst-field.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1015 B
Rust
Raw Normal View History

2023-04-21 03:53:34 -05:00
#![feature(offset_of, extern_types)]
2022-09-11 02:37:49 -05:00
use std::mem::offset_of;
2023-04-21 03:53:34 -05:00
struct Alpha {
2022-09-11 02:37:49 -05:00
x: u8,
y: u16,
2023-04-21 03:53:34 -05:00
z: [u8],
}
trait Trait {}
struct Beta {
x: u8,
y: u16,
z: dyn Trait,
}
extern {
type Extern;
}
struct Gamma {
x: u8,
y: u16,
z: Extern,
2022-09-11 02:37:49 -05:00
}
struct Delta<T: ?Sized> {
x: u8,
y: u16,
z: T,
}
2022-09-11 02:37:49 -05:00
fn main() {
2023-04-21 03:53:34 -05:00
offset_of!(Alpha, z); //~ ERROR the size for values of type
offset_of!(Beta, z); //~ ERROR the size for values of type
offset_of!(Gamma, z); //~ ERROR the size for values of type
offset_of!((u8, dyn Trait), 0); // ok
offset_of!((u8, dyn Trait), 1); //~ ERROR the size for values of type
2022-09-11 02:37:49 -05:00
}
fn delta() {
offset_of!(Delta<Alpha>, z); //~ ERROR the size for values of type
offset_of!(Delta<Extern>, z); //~ ERROR the size for values of type
offset_of!(Delta<dyn Trait>, z); //~ ERROR the size for values of type
}
fn generic_with_maybe_sized<T: ?Sized>() -> usize {
offset_of!(Delta<T>, z) //~ ERROR the size for values of type
}