From 93993c77f55047cc1774fdfee4bcca9d43592c2a Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sat, 21 Sep 2024 08:48:28 -0700 Subject: [PATCH] compiler: Accept "improper" ctypes in extern "rust-cold" fn --- compiler/rustc_lint/src/types.rs | 5 ++++- .../ui/lint/rust-cold-fn-accept-improper-ctypes.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/ui/lint/rust-cold-fn-accept-improper-ctypes.rs diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index f9d0cd49708ae..3d042f217452f 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1320,7 +1320,10 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } fn is_internal_abi(&self, abi: SpecAbi) -> bool { - matches!(abi, SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustIntrinsic) + matches!( + abi, + SpecAbi::Rust | SpecAbi::RustCall | SpecAbi::RustCold | SpecAbi::RustIntrinsic + ) } /// Find any fn-ptr types with external ABIs in `ty`. diff --git a/tests/ui/lint/rust-cold-fn-accept-improper-ctypes.rs b/tests/ui/lint/rust-cold-fn-accept-improper-ctypes.rs new file mode 100644 index 0000000000000..dc929e14527f4 --- /dev/null +++ b/tests/ui/lint/rust-cold-fn-accept-improper-ctypes.rs @@ -0,0 +1,14 @@ +//@ check-pass +#![feature(rust_cold_cc)] + +// extern "rust-cold" is a "Rust" ABI so we accept `repr(Rust)` types as arg/ret without warnings. + +pub extern "rust-cold" fn f(_: ()) -> Result<(), ()> { + Ok(()) +} + +extern "rust-cold" { + pub fn g(_: ()) -> Result<(), ()>; +} + +fn main() {}