From 2beadda23d5000879d110a12add38aa7a156a7f4 Mon Sep 17 00:00:00 2001 From: Folkert de Vries Date: Sun, 28 Jun 2026 00:47:14 +0200 Subject: [PATCH] stabilize `extern "custom"` --- compiler/rustc_ast_lowering/src/stability.rs | 4 +- compiler/rustc_feature/src/accepted.rs | 2 + compiler/rustc_feature/src/unstable.rs | 2 - .../compiler-builtins/src/lib.rs | 1 - .../src/compiler-flags/instrument-mcount.md | 1 - tests/ui/abi/bad-custom.rs | 1 - tests/ui/abi/bad-custom.stderr | 70 +++++------ tests/ui/abi/custom.rs | 1 - .../feature-gates/feature-gate-abi-custom.rs | 51 -------- .../feature-gate-abi-custom.stderr | 117 ------------------ 10 files changed, 38 insertions(+), 212 deletions(-) delete mode 100644 tests/ui/feature-gates/feature-gate-abi-custom.rs delete mode 100644 tests/ui/feature-gates/feature-gate-abi-custom.stderr diff --git a/compiler/rustc_ast_lowering/src/stability.rs b/compiler/rustc_ast_lowering/src/stability.rs index b58087e4aa3a6..d86393ca0e464 100644 --- a/compiler/rustc_ast_lowering/src/stability.rs +++ b/compiler/rustc_ast_lowering/src/stability.rs @@ -70,6 +70,7 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> { ExternAbi::Rust | ExternAbi::C { .. } | ExternAbi::Cdecl { .. } + | ExternAbi::Custom | ExternAbi::Stdcall { .. } | ExternAbi::Fastcall { .. } | ExternAbi::Thiscall { .. } @@ -144,9 +145,6 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> { feature: sym::cmse_nonsecure_entry, explain: GateReason::Experimental, }), - ExternAbi::Custom => { - Err(UnstableAbi { abi, feature: sym::abi_custom, explain: GateReason::Experimental }) - } ExternAbi::Swift => { Err(UnstableAbi { abi, feature: sym::abi_swift, explain: GateReason::Experimental }) } diff --git a/compiler/rustc_feature/src/accepted.rs b/compiler/rustc_feature/src/accepted.rs index 63c35ad4e122b..0943f5a1ed08e 100644 --- a/compiler/rustc_feature/src/accepted.rs +++ b/compiler/rustc_feature/src/accepted.rs @@ -46,6 +46,8 @@ declare_features! ( /// Allows `#[target_feature(...)]` on aarch64 platforms (accepted, aarch64_target_feature, "1.61.0", Some(44839)), + /// Allows `extern "custom" fn()`. + (accepted, abi_custom, "CURRENT_RUSTC_VERSION", Some(140829)), /// Allows using the `efiapi` ABI. (accepted, abi_efiapi, "1.68.0", Some(65815)), /// Allows the sysV64 ABI to be specified on all platforms diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index fc38d9de6e143..a7799602049b2 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -370,8 +370,6 @@ declare_features! ( (unstable, abi_avr_interrupt, "1.45.0", Some(69664)), /// Allows `extern "cmse-nonsecure-call" fn()`. (unstable, abi_cmse_nonsecure_call, "1.90.0", Some(81391)), - /// Allows `extern "custom" fn()`. - (unstable, abi_custom, "1.89.0", Some(140829)), /// Allows `extern "gpu-kernel" fn()`. (unstable, abi_gpu_kernel, "1.86.0", Some(135467)), /// Allows `extern "msp430-interrupt" fn()`. diff --git a/library/compiler-builtins/compiler-builtins/src/lib.rs b/library/compiler-builtins/compiler-builtins/src/lib.rs index 9e847206caf19..6bde5195e8af4 100644 --- a/library/compiler-builtins/compiler-builtins/src/lib.rs +++ b/library/compiler-builtins/compiler-builtins/src/lib.rs @@ -1,6 +1,5 @@ #![cfg_attr(feature = "compiler-builtins", compiler_builtins)] #![cfg_attr(all(target_family = "wasm"), feature(wasm_numeric_instr))] -#![feature(abi_custom)] #![feature(abi_unadjusted)] #![feature(asm_experimental_arch)] #![feature(cfg_target_has_atomic)] diff --git a/src/doc/unstable-book/src/compiler-flags/instrument-mcount.md b/src/doc/unstable-book/src/compiler-flags/instrument-mcount.md index 376b509048dab..580cbf8c9614c 100644 --- a/src/doc/unstable-book/src/compiler-flags/instrument-mcount.md +++ b/src/doc/unstable-book/src/compiler-flags/instrument-mcount.md @@ -38,7 +38,6 @@ The following example can be compiled with `-Zinstrument-mcount=yes` or `-Zinstr ```rust #![feature(instrument_fn)] -#![feature(abi_custom)] fn main() { // Ensure all the early startup occurs before attempting to call this trivial, single-threaded diff --git a/tests/ui/abi/bad-custom.rs b/tests/ui/abi/bad-custom.rs index 7c881134ccb4c..9630a23b7fef1 100644 --- a/tests/ui/abi/bad-custom.rs +++ b/tests/ui/abi/bad-custom.rs @@ -1,7 +1,6 @@ //@ edition: 2021 //@ check-fail //@ needs-asm-support -#![feature(abi_custom)] #[unsafe(naked)] extern "custom" fn must_be_unsafe(a: i64) -> i64 { diff --git a/tests/ui/abi/bad-custom.stderr b/tests/ui/abi/bad-custom.stderr index d7c9cae35c7b3..43569b1501b86 100644 --- a/tests/ui/abi/bad-custom.stderr +++ b/tests/ui/abi/bad-custom.stderr @@ -1,5 +1,5 @@ error: functions with the "custom" ABI must be unsafe - --> $DIR/bad-custom.rs:7:1 + --> $DIR/bad-custom.rs:6:1 | LL | extern "custom" fn must_be_unsafe(a: i64) -> i64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -10,7 +10,7 @@ LL | unsafe extern "custom" fn must_be_unsafe(a: i64) -> i64 { | ++++++ error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:7:35 + --> $DIR/bad-custom.rs:6:35 | LL | extern "custom" fn must_be_unsafe(a: i64) -> i64 { | ^^^^^^ ^^^ @@ -23,7 +23,7 @@ LL + extern "custom" fn must_be_unsafe() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:14:41 + --> $DIR/bad-custom.rs:13:41 | LL | unsafe extern "custom" fn no_parameters(a: i64) { | ^^^^^^ @@ -36,7 +36,7 @@ LL + unsafe extern "custom" fn no_parameters() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:20:47 + --> $DIR/bad-custom.rs:19:47 | LL | unsafe extern "custom" fn no_return_type() -> i64 { | ^^^ @@ -49,7 +49,7 @@ LL + unsafe extern "custom" fn no_return_type() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:25:34 + --> $DIR/bad-custom.rs:24:34 | LL | unsafe extern "custom" fn double(a: i64) -> i64 { | ^^^^^^ ^^^ @@ -62,7 +62,7 @@ LL + unsafe extern "custom" fn double() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:34:39 + --> $DIR/bad-custom.rs:33:39 | LL | unsafe extern "custom" fn is_even(self) -> bool { | ^^^^ ^^^^ @@ -75,7 +75,7 @@ LL + unsafe extern "custom" fn is_even() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:42:43 + --> $DIR/bad-custom.rs:41:43 | LL | unsafe extern "custom" fn bitwise_not(a: i64) -> i64 { | ^^^^^^ ^^^ @@ -88,7 +88,7 @@ LL + unsafe extern "custom" fn bitwise_not() { | error: functions with the "custom" ABI must be unsafe - --> $DIR/bad-custom.rs:52:5 + --> $DIR/bad-custom.rs:51:5 | LL | extern "custom" fn negate(a: i64) -> i64; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -99,7 +99,7 @@ LL | unsafe extern "custom" fn negate(a: i64) -> i64; | ++++++ error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:52:31 + --> $DIR/bad-custom.rs:51:31 | LL | extern "custom" fn negate(a: i64) -> i64; | ^^^^^^ ^^^ @@ -112,7 +112,7 @@ LL + extern "custom" fn negate(); | error: functions with the "custom" ABI must be unsafe - --> $DIR/bad-custom.rs:58:5 + --> $DIR/bad-custom.rs:57:5 | LL | extern "custom" fn negate(a: i64) -> i64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -123,7 +123,7 @@ LL | unsafe extern "custom" fn negate(a: i64) -> i64 { | ++++++ error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:58:31 + --> $DIR/bad-custom.rs:57:31 | LL | extern "custom" fn negate(a: i64) -> i64 { | ^^^^^^ ^^^ @@ -136,7 +136,7 @@ LL + extern "custom" fn negate() { | error: invalid signature for `extern "custom"` function - --> $DIR/bad-custom.rs:67:18 + --> $DIR/bad-custom.rs:66:18 | LL | fn increment(a: i64) -> i64; | ^^^^^^ ^^^ @@ -149,7 +149,7 @@ LL + fn increment(); | error: foreign functions with the "custom" ABI cannot be safe - --> $DIR/bad-custom.rs:70:5 + --> $DIR/bad-custom.rs:69:5 | LL | safe fn extern_cannot_be_safe(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -161,7 +161,7 @@ LL + fn extern_cannot_be_safe(); | error: functions with the "custom" ABI cannot be `async` - --> $DIR/bad-custom.rs:97:1 + --> $DIR/bad-custom.rs:96:1 | LL | async unsafe extern "custom" fn no_async_fn() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -173,7 +173,7 @@ LL + unsafe extern "custom" fn no_async_fn() { | error: items with the "custom" ABI can only be declared externally or defined via naked functions - --> $DIR/bad-custom.rs:97:1 + --> $DIR/bad-custom.rs:96:1 | LL | async unsafe extern "custom" fn no_async_fn() { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -185,7 +185,7 @@ LL | async unsafe extern "custom" fn no_async_fn() { | error[E0277]: expected a `Fn()` closure, found `unsafe extern "custom" fn()` - --> $DIR/bad-custom.rs:102:64 + --> $DIR/bad-custom.rs:101:64 | LL | fn no_promotion_to_fn_trait(f: unsafe extern "custom" fn()) -> impl Fn() { | ^^^^^^^^^ call the function in a closure: `|| unsafe { /* code */ }` @@ -198,7 +198,7 @@ LL | f = note: unsafe function cannot be called generically without an unsafe block error: items with the "custom" ABI can only be declared externally or defined via naked functions - --> $DIR/bad-custom.rs:25:1 + --> $DIR/bad-custom.rs:24:1 | LL | unsafe extern "custom" fn double(a: i64) -> i64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -210,7 +210,7 @@ LL | unsafe extern "custom" fn double(a: i64) -> i64 { | error: items with the "custom" ABI can only be declared externally or defined via naked functions - --> $DIR/bad-custom.rs:34:5 + --> $DIR/bad-custom.rs:33:5 | LL | unsafe extern "custom" fn is_even(self) -> bool { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -222,7 +222,7 @@ LL | unsafe extern "custom" fn is_even(self) -> bool { | error: items with the "custom" ABI can only be declared externally or defined via naked functions - --> $DIR/bad-custom.rs:42:5 + --> $DIR/bad-custom.rs:41:5 | LL | unsafe extern "custom" fn bitwise_not(a: i64) -> i64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -234,7 +234,7 @@ LL | unsafe extern "custom" fn bitwise_not(a: i64) -> i64 { | error: items with the "custom" ABI can only be declared externally or defined via naked functions - --> $DIR/bad-custom.rs:58:5 + --> $DIR/bad-custom.rs:57:5 | LL | extern "custom" fn negate(a: i64) -> i64 { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -246,91 +246,91 @@ LL | extern "custom" fn negate(a: i64) -> i64 { | error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:75:14 + --> $DIR/bad-custom.rs:74:14 | LL | unsafe { f(x) } | ^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:75:14 + --> $DIR/bad-custom.rs:74:14 | LL | unsafe { f(x) } | ^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:80:14 + --> $DIR/bad-custom.rs:79:14 | LL | unsafe { f(x) } | ^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:80:14 + --> $DIR/bad-custom.rs:79:14 | LL | unsafe { f(x) } | ^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:87:14 + --> $DIR/bad-custom.rs:86:14 | LL | unsafe { f(x) } | ^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:87:14 + --> $DIR/bad-custom.rs:86:14 | LL | unsafe { f(x) } | ^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:109:20 + --> $DIR/bad-custom.rs:108:20 | LL | assert_eq!(double(21), 42); | ^^^^^^^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:109:20 + --> $DIR/bad-custom.rs:108:20 | LL | assert_eq!(double(21), 42); | ^^^^^^^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:112:29 + --> $DIR/bad-custom.rs:111:29 | LL | assert_eq!(unsafe { increment(41) }, 42); | ^^^^^^^^^^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:112:29 + --> $DIR/bad-custom.rs:111:29 | LL | assert_eq!(unsafe { increment(41) }, 42); | ^^^^^^^^^^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:115:17 + --> $DIR/bad-custom.rs:114:17 | LL | assert!(Thing(41).is_even()); | ^^^^^^^^^^^^^^^^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:115:17 + --> $DIR/bad-custom.rs:114:17 | LL | assert!(Thing(41).is_even()); | ^^^^^^^^^^^^^^^^^^^ error: functions with the "custom" ABI cannot be called - --> $DIR/bad-custom.rs:118:20 + --> $DIR/bad-custom.rs:117:20 | LL | assert_eq!(Thing::bitwise_not(42), !42); | ^^^^^^^^^^^^^^^^^^^^^^ | note: an `extern "custom"` function can only be called using inline assembly - --> $DIR/bad-custom.rs:118:20 + --> $DIR/bad-custom.rs:117:20 | LL | assert_eq!(Thing::bitwise_not(42), !42); | ^^^^^^^^^^^^^^^^^^^^^^ error[E0015]: inline assembly is not allowed in constant functions - --> $DIR/bad-custom.rs:93:5 + --> $DIR/bad-custom.rs:92:5 | LL | std::arch::naked_asm!("") | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/abi/custom.rs b/tests/ui/abi/custom.rs index 0f6ff77f58084..5a1cba19b7352 100644 --- a/tests/ui/abi/custom.rs +++ b/tests/ui/abi/custom.rs @@ -3,7 +3,6 @@ // //@ run-pass //@ only-x86_64 -#![feature(abi_custom)] use std::arch::{asm, global_asm, naked_asm}; diff --git a/tests/ui/feature-gates/feature-gate-abi-custom.rs b/tests/ui/feature-gates/feature-gate-abi-custom.rs deleted file mode 100644 index ca0b8337bbb75..0000000000000 --- a/tests/ui/feature-gates/feature-gate-abi-custom.rs +++ /dev/null @@ -1,51 +0,0 @@ -//@ add-minicore -//@ needs-asm-support -#![no_core] -#![feature(no_core, lang_items)] -#![crate_type = "rlib"] - -extern crate minicore; -use minicore::*; - -#[unsafe(naked)] -unsafe extern "custom" fn f7() { - //~^ ERROR "custom" ABI is experimental - naked_asm!("") -} -trait Tr { - extern "custom" fn m7(); - //~^ ERROR "custom" ABI is experimental - //~| ERROR functions with the "custom" ABI must be unsafe - #[unsafe(naked)] - extern "custom" fn dm7() { - //~^ ERROR "custom" ABI is experimental - //~| ERROR functions with the "custom" ABI must be unsafe - naked_asm!("") - } -} - -struct S; - -// Methods in trait impl -impl Tr for S { - #[unsafe(naked)] - extern "custom" fn m7() { - //~^ ERROR "custom" ABI is experimental - //~| ERROR functions with the "custom" ABI must be unsafe - naked_asm!("") - } -} - -// Methods in inherent impl -impl S { - #[unsafe(naked)] - extern "custom" fn im7() { - //~^ ERROR "custom" ABI is experimental - //~| ERROR functions with the "custom" ABI must be unsafe - naked_asm!("") - } -} - -type A7 = extern "custom" fn(); //~ ERROR "custom" ABI is experimental - -extern "custom" {} //~ ERROR "custom" ABI is experimental diff --git a/tests/ui/feature-gates/feature-gate-abi-custom.stderr b/tests/ui/feature-gates/feature-gate-abi-custom.stderr deleted file mode 100644 index e359dbb5ebe1d..0000000000000 --- a/tests/ui/feature-gates/feature-gate-abi-custom.stderr +++ /dev/null @@ -1,117 +0,0 @@ -error: functions with the "custom" ABI must be unsafe - --> $DIR/feature-gate-abi-custom.rs:16:5 - | -LL | extern "custom" fn m7(); - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: add the `unsafe` keyword to this definition - | -LL | unsafe extern "custom" fn m7(); - | ++++++ - -error: functions with the "custom" ABI must be unsafe - --> $DIR/feature-gate-abi-custom.rs:20:5 - | -LL | extern "custom" fn dm7() { - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: add the `unsafe` keyword to this definition - | -LL | unsafe extern "custom" fn dm7() { - | ++++++ - -error: functions with the "custom" ABI must be unsafe - --> $DIR/feature-gate-abi-custom.rs:32:5 - | -LL | extern "custom" fn m7() { - | ^^^^^^^^^^^^^^^^^^^^^^^ - | -help: add the `unsafe` keyword to this definition - | -LL | unsafe extern "custom" fn m7() { - | ++++++ - -error: functions with the "custom" ABI must be unsafe - --> $DIR/feature-gate-abi-custom.rs:42:5 - | -LL | extern "custom" fn im7() { - | ^^^^^^^^^^^^^^^^^^^^^^^^ - | -help: add the `unsafe` keyword to this definition - | -LL | unsafe extern "custom" fn im7() { - | ++++++ - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:11:15 - | -LL | unsafe extern "custom" fn f7() { - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:16:12 - | -LL | extern "custom" fn m7(); - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:20:12 - | -LL | extern "custom" fn dm7() { - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:32:12 - | -LL | extern "custom" fn m7() { - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:42:12 - | -LL | extern "custom" fn im7() { - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:49:18 - | -LL | type A7 = extern "custom" fn(); - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error[E0658]: the extern "custom" ABI is experimental and subject to change - --> $DIR/feature-gate-abi-custom.rs:51:8 - | -LL | extern "custom" {} - | ^^^^^^^^ - | - = note: see issue #140829 for more information - = help: add `#![feature(abi_custom)]` to the crate attributes to enable - = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date - -error: aborting due to 11 previous errors - -For more information about this error, try `rustc --explain E0658`.