From 7632fab6689770d0f482851781e9735d7b8f5f5e Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 1 Jun 2025 15:20:27 -0700 Subject: [PATCH] tests: Adopt ABI transmute tests from crashtests --- tests/auxiliary/minicore.rs | 7 +++++++ tests/crashes/138738.rs | 7 ------- tests/ui/abi/unsupported-abi-transmute.rs | 15 +++++++++++++++ tests/ui/abi/unsupported-abi-transmute.stderr | 9 +++++++++ 4 files changed, 31 insertions(+), 7 deletions(-) delete mode 100644 tests/crashes/138738.rs create mode 100644 tests/ui/abi/unsupported-abi-transmute.rs create mode 100644 tests/ui/abi/unsupported-abi-transmute.stderr diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index db11549382fc..3e9841b179cb 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -16,6 +16,7 @@ #![feature( no_core, + intrinsics, lang_items, auto_traits, freeze_impls, @@ -196,3 +197,9 @@ impl<'a, 'b: 'a, T: PointeeSized + Unsize, U: PointeeSized> CoerceUnsized<&'a trait Drop { fn drop(&mut self); } + +pub mod mem { + #[rustc_nounwind] + #[rustc_intrinsic] + pub unsafe fn transmute(src: Src) -> Dst; +} diff --git a/tests/crashes/138738.rs b/tests/crashes/138738.rs deleted file mode 100644 index 74e5effa56f5..000000000000 --- a/tests/crashes/138738.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ known-bug: #138738 -//@ only-x86_64 - -#![feature(abi_ptx)] -fn main() { - let a = unsafe { core::mem::transmute::(4) }(2); -} diff --git a/tests/ui/abi/unsupported-abi-transmute.rs b/tests/ui/abi/unsupported-abi-transmute.rs new file mode 100644 index 000000000000..31501bc6d108 --- /dev/null +++ b/tests/ui/abi/unsupported-abi-transmute.rs @@ -0,0 +1,15 @@ +//@ add-core-stubs +//@ compile-flags: --crate-type=lib --target x86_64-unknown-none +//@ needs-llvm-components: x86 +//@ edition: 2018 +#![no_core] +#![feature(no_core, lang_items)] +extern crate minicore; +use minicore::*; + +// Check we error before unsupported ABIs reach codegen stages. + +fn anything() { + let a = unsafe { mem::transmute::(4) }(2); + //~^ ERROR: is not a supported ABI for the current target [E0570] +} diff --git a/tests/ui/abi/unsupported-abi-transmute.stderr b/tests/ui/abi/unsupported-abi-transmute.stderr new file mode 100644 index 000000000000..63056180c71c --- /dev/null +++ b/tests/ui/abi/unsupported-abi-transmute.stderr @@ -0,0 +1,9 @@ +error[E0570]: "thiscall" is not a supported ABI for the current target + --> $DIR/unsupported-abi-transmute.rs:13:53 + | +LL | let a = unsafe { mem::transmute::(4) }(2); + | ^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0570`.