Skip to content

Commit 855060a

Browse files
committed
Auto merge of #118032 - RalfJung:char-u32, r=Mark-Simulacrum
guarantee that char and u32 are ABI-compatible In rust-lang/rust#116894 we added a guarantee that `char` has the same alignment as `u32`, but there is still one axis where these types could differ: function call ABI. So let's nail that down as well: in a function signature, `char` and `u32` are completely equivalent. This is a new stable guarantee, so it will need t-lang approval.
2 parents 9cc878d + e28045d commit 855060a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

tests/pass/function_calls/abi_compat.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ fn main() {
7171
test_abi_compat(0isize, 0i64);
7272
}
7373
test_abi_compat(42u32, num::NonZeroU32::new(1).unwrap());
74+
// - `char` and `u32`.
75+
test_abi_compat(42u32, 'x');
7476
// - Reference/pointer types with the same pointee.
7577
test_abi_compat(&0u32, &0u32 as *const u32);
7678
test_abi_compat(&mut 0u32 as *mut u32, Box::new(0u32));
@@ -81,7 +83,7 @@ fn main() {
8183
test_abi_compat(main as fn(), id::<i32> as fn(i32) -> i32);
8284
// - 1-ZST
8385
test_abi_compat((), [0u8; 0]);
84-
// - Guaranteed null-pointer-optimizations.
86+
// - Guaranteed null-pointer-optimizations (RFC 3391).
8587
test_abi_compat(&0u32 as *const u32, Some(&0u32));
8688
test_abi_compat(main as fn(), Some(main as fn()));
8789
test_abi_compat(0u32, Some(num::NonZeroU32::new(1).unwrap()));
@@ -103,6 +105,8 @@ fn main() {
103105
test_abi_newtype::<Option<num::NonZeroU32>>();
104106

105107
// Extra test for assumptions made by arbitrary-self-dyn-receivers.
108+
// This is interesting since these types are not `repr(transparent)`. So this is not part of our
109+
// public ABI guarantees, but is relied on by the compiler.
106110
let rc = Rc::new(0);
107111
let rc_ptr: *mut i32 = unsafe { mem::transmute_copy(&rc) };
108112
test_abi_compat(rc, rc_ptr);

0 commit comments

Comments
 (0)