]> git.lizzy.rs Git - rust.git/blob - tests/ui/extern/extern-types-thin-pointer.rs
Rollup merge of #107769 - compiler-errors:pointer-like, r=eholk
[rust.git] / tests / ui / extern / extern-types-thin-pointer.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Test that pointers and references to extern types are thin, ie they have the same size and
4 // alignment as a pointer to ().
5 #![feature(extern_types)]
6
7 use std::mem::{align_of, size_of};
8
9 extern "C" {
10     type A;
11 }
12
13 struct Foo {
14     x: u8,
15     tail: A,
16 }
17
18 struct Bar<T: ?Sized> {
19     x: u8,
20     tail: T,
21 }
22
23 fn assert_thin<T: ?Sized>() {
24     assert_eq!(size_of::<*const T>(), size_of::<*const ()>());
25     assert_eq!(align_of::<*const T>(), align_of::<*const ()>());
26
27     assert_eq!(size_of::<*mut T>(), size_of::<*mut ()>());
28     assert_eq!(align_of::<*mut T>(), align_of::<*mut ()>());
29
30     assert_eq!(size_of::<&T>(), size_of::<&()>());
31     assert_eq!(align_of::<&T>(), align_of::<&()>());
32
33     assert_eq!(size_of::<&mut T>(), size_of::<&mut ()>());
34     assert_eq!(align_of::<&mut T>(), align_of::<&mut ()>());
35 }
36
37 fn main() {
38     assert_thin::<A>();
39     assert_thin::<Foo>();
40     assert_thin::<Bar<A>>();
41     assert_thin::<Bar<Bar<A>>>();
42 }