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
|
|
|
}
|
|
|
|
|
2023-05-16 21:56:59 -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
|
2023-06-01 19:41:02 -05:00
|
|
|
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
|
|
|
}
|
2023-05-16 21:56:59 -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
|
2023-05-17 15:10:36 -05:00
|
|
|
offset_of!(Delta<dyn Trait>, z); //~ ERROR the size for values of type
|
2023-05-16 21:56:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn generic_with_maybe_sized<T: ?Sized>() -> usize {
|
|
|
|
offset_of!(Delta<T>, z) //~ ERROR the size for values of type
|
|
|
|
}
|