add foregin type tests
add tests/ui/rfcs/rfc-1861-extern-types/comparison.rs
This commit is contained in:
parent
88ad3d44ca
commit
e86cfa0577
1 changed files with 35 additions and 0 deletions
35
tests/ui/rfcs/rfc-1861-extern-types/comparison.rs
Normal file
35
tests/ui/rfcs/rfc-1861-extern-types/comparison.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Foreign type tests not covering all operations
|
||||
//@ only-nightly
|
||||
//@ build-pass
|
||||
|
||||
#![feature(extern_types)]
|
||||
|
||||
#![allow(ambiguous_wide_pointer_comparisons)]
|
||||
|
||||
extern "C" {
|
||||
type ForeignType;
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Example {
|
||||
field: ForeignType,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// pointer comparison
|
||||
let a = std::ptr::null::<ForeignType>();
|
||||
let b = std::ptr::null::<ForeignType>();
|
||||
|
||||
assert!(a == b);
|
||||
|
||||
// field address computation
|
||||
let p = std::ptr::null::<Example>();
|
||||
unsafe {
|
||||
let _ = &(*p).field;
|
||||
}
|
||||
|
||||
// pointer casts involving extern types
|
||||
let raw = std::ptr::null::<()>();
|
||||
let ext = raw as *const ForeignType;
|
||||
let _ = ext as *const ();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue