diff options
| author | Jonas Böttiger <jonasboettiger@icloud.com> | 2024-11-07 13:08:27 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-07 13:08:27 +0100 |
| commit | 6b5a58c265dd8a0775aee2ea992510b056b3267e (patch) | |
| tree | 5ab4353977966a0a2c17488583d88ff097f5f0c0 /src/tools | |
| parent | 9200cbc71230a86b8a70481b625d93a4fa5ef523 (diff) | |
| parent | b2fe71a2fe865902c62c78ee42c949bf3fd4a519 (diff) | |
Rollup merge of #132057 - RalfJung:miri-abi-compat, r=wesleywiser
miri: update ABI compat checks to accept Option-like types This implements the t-lang decision described [here](https://github.com/rust-lang/rust/pull/130628#issuecomment-2402761599). Fixes https://github.com/rust-lang/miri/issues/3983
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/miri/tests/pass/function_calls/abi_compat.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/tools/miri/tests/pass/function_calls/abi_compat.rs b/src/tools/miri/tests/pass/function_calls/abi_compat.rs index b5feac8c677..cd48bd2accb 100644 --- a/src/tools/miri/tests/pass/function_calls/abi_compat.rs +++ b/src/tools/miri/tests/pass/function_calls/abi_compat.rs @@ -1,3 +1,5 @@ +#![feature(never_type)] + use std::rc::Rc; use std::{mem, num, ptr}; @@ -12,6 +14,18 @@ fn id<T>(x: T) -> T { x } +#[derive(Copy, Clone)] +enum Either<T, U> { + Left(T), + Right(U), +} +#[derive(Copy, Clone)] +enum Either2<T, U> { + Left(T), + #[allow(unused)] + Right(U, ()), +} + fn test_abi_compat<T: Clone, U: Clone>(t: T, u: U) { fn id<T>(x: T) -> T { x @@ -81,6 +95,8 @@ fn main() { test_abi_compat(main as fn(), id::<i32> as fn(i32) -> i32); // - 1-ZST test_abi_compat((), [0u8; 0]); + + // Guaranteed null-pointer-layout optimizations: // - Guaranteed Option<X> null-pointer-optimizations (RFC 3391). test_abi_compat(&0u32 as *const u32, Some(&0u32)); test_abi_compat(main as fn(), Some(main as fn())); @@ -89,6 +105,7 @@ fn main() { test_abi_compat(0u32, Some(Wrapper(num::NonZeroU32::new(1u32).unwrap()))); // - Guaranteed Result<X, ZST1> does the same as Option<X> (RFC 3391) test_abi_compat(&0u32 as *const u32, Result::<_, ()>::Ok(&0u32)); + test_abi_compat(&0u32 as *const u32, Result::<_, !>::Ok(&0u32)); test_abi_compat(main as fn(), Result::<_, ()>::Ok(main as fn())); test_abi_compat(0u32, Result::<_, ()>::Ok(num::NonZeroU32::new(1).unwrap())); test_abi_compat(&0u32 as *const u32, Result::<_, ()>::Ok(Wrapper(&0u32))); @@ -99,6 +116,13 @@ fn main() { test_abi_compat(0u32, Result::<(), _>::Err(num::NonZeroU32::new(1).unwrap())); test_abi_compat(&0u32 as *const u32, Result::<(), _>::Err(Wrapper(&0u32))); test_abi_compat(0u32, Result::<(), _>::Err(Wrapper(num::NonZeroU32::new(1).unwrap()))); + // - Guaranteed null-pointer-optimizations for custom option-like types + test_abi_compat(&0u32 as *const u32, Either::<_, ()>::Left(&0u32)); + test_abi_compat(&0u32 as *const u32, Either::<_, !>::Left(&0u32)); + test_abi_compat(&0u32 as *const u32, Either::<(), _>::Right(&0u32)); + test_abi_compat(&0u32 as *const u32, Either::<!, _>::Right(&0u32)); + test_abi_compat(&0u32 as *const u32, Either2::<_, ()>::Left(&0u32)); + test_abi_compat(&0u32 as *const u32, Either2::<_, [u8; 0]>::Left(&0u32)); // These must work for *any* type, since we guarantee that `repr(transparent)` is ABI-compatible // with the wrapped field. |
