]> git.lizzy.rs Git - rust.git/blob - tests/ui/extern/extern-types-pointer-cast.rs
Merge commit '7f27e2e74ef957baa382dc05cf08df6368165c74' into clippyup
[rust.git] / tests / ui / extern / extern-types-pointer-cast.rs
1 // run-pass
2 #![allow(dead_code)]
3 // Test that pointers to extern types can be cast from/to usize,
4 // despite being !Sized.
5 #![feature(extern_types)]
6
7 extern "C" {
8     type A;
9 }
10
11 struct Foo {
12     x: u8,
13     tail: A,
14 }
15
16 struct Bar<T: ?Sized> {
17     x: u8,
18     tail: T,
19 }
20
21 #[cfg(target_pointer_width = "32")]
22 const MAGIC: usize = 0xdeadbeef;
23 #[cfg(target_pointer_width = "64")]
24 const MAGIC: usize = 0x12345678deadbeef;
25
26 fn main() {
27     assert_eq!((MAGIC as *const A) as usize, MAGIC);
28     assert_eq!((MAGIC as *const Foo) as usize, MAGIC);
29     assert_eq!((MAGIC as *const Bar<A>) as usize, MAGIC);
30     assert_eq!((MAGIC as *const Bar<Bar<A>>) as usize, MAGIC);
31 }