mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #151475 - KaiTomotake:add-foreign-type-tests, r=Kivooeo
add foregin type tests for issue 64458 add tests/ui/rfcs/rfc-1861-extern-types/comparison.rs close rust-lang/rust#64458
This commit is contained in:
@@ -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 ();
|
||||
}
|
||||
Reference in New Issue
Block a user