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:
Stuart Cook 2026-01-29 22:34:09 +11:00 committed by GitHub
commit 36a2726bb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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 ();
}