From d2c767fc1c48ca6269750a21865c56675c29c0da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Tue, 5 May 2026 13:46:38 +0200 Subject: [PATCH 1/3] rustc: riscv: promote d, e, and f target_features to CfgStableToggleUnstable --- compiler/rustc_target/src/target_features.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_target/src/target_features.rs b/compiler/rustc_target/src/target_features.rs index e2bf1c48b7b47..632f9c5f25700 100644 --- a/compiler/rustc_target/src/target_features.rs +++ b/compiler/rustc_target/src/target_features.rs @@ -610,9 +610,9 @@ static RISCV_FEATURES: &[(&str, Stability, ImpliedFeatures)] = &[ ("a", Stable, &["zaamo", "zalrsc"]), ("b", Stable, &["zba", "zbb", "zbs"]), ("c", Stable, &["zca"]), - ("d", Unstable(sym::riscv_target_feature), &["f"]), - ("e", Unstable(sym::riscv_target_feature), &[]), - ("f", Unstable(sym::riscv_target_feature), &["zicsr"]), + ("d", CfgStableToggleUnstable(sym::riscv_target_feature), &["f"]), + ("e", CfgStableToggleUnstable(sym::riscv_target_feature), &[]), + ("f", CfgStableToggleUnstable(sym::riscv_target_feature), &["zicsr"]), ( "forced-atomics", Stability::Forbidden { reason: "unsound because it changes the ABI of atomic operations" }, From d396920b4ee9602542b9ee6282ff5a3c4c6e981f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Wed, 6 May 2026 08:13:37 +0200 Subject: [PATCH 2/3] rustc: riscv: adapt target_feature tests --- .../abi-incompatible-target-feature-flag-enable.riscv.stderr | 2 +- .../abi-required-target-feature-flag-disable.riscv.stderr | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr index 11ec86b1e6d85..2183513bf3b97 100644 --- a/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr +++ b/tests/ui/target-feature/abi-incompatible-target-feature-flag-enable.riscv.stderr @@ -1,6 +1,6 @@ warning: unstable feature specified for `-Ctarget-feature`: `d` | - = note: this feature is not stably supported; its behavior can change in the future + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future warning: target feature `d` must be disabled to ensure that the ABI of the current target can be implemented correctly | diff --git a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr index cc225b353df13..7fa1cc299b229 100644 --- a/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr +++ b/tests/ui/target-feature/abi-required-target-feature-flag-disable.riscv.stderr @@ -1,6 +1,6 @@ warning: unstable feature specified for `-Ctarget-feature`: `d` | - = note: this feature is not stably supported; its behavior can change in the future + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future warning: target feature `d` must be enabled to ensure that the ABI of the current target can be implemented correctly | From 4e9a3ded2a63a567a21aa245cdd8e8a2e065d86c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rom=C3=A1n=20C=C3=A1rdenas=20Rodr=C3=ADguez?= Date: Wed, 6 May 2026 11:47:21 +0200 Subject: [PATCH 3/3] rustc: riscv: add tests for cfg-only stable features --- ...unstable-target-feature-attribute-riscv.rs | 17 ++++++++++++++ ...able-target-feature-attribute-riscv.stderr | 23 +++++++++++++++++++ ...stable-target-feature-flag-enable-riscv.rs | 17 ++++++++++++++ ...le-target-feature-flag-enable-riscv.stderr | 10 ++++++++ 4 files changed, 67 insertions(+) create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs create mode 100644 tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs new file mode 100644 index 0000000000000..24d42e3df44d3 --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs @@ -0,0 +1,17 @@ +//! Ensure cfg-only stable target_features trigger errors when enabled via attribute. +//@ compile-flags: --crate-type=lib +//@ compile-flags: --target=riscv64gc-unknown-none-elf +//@ needs-llvm-components: riscv +//@ add-minicore +//@ ignore-backends: gcc +#![feature(no_core)] +#![no_core] + +extern crate minicore; +use minicore::*; + +#[target_feature(enable = "v")] +//~^ERROR: the target feature `v` is currently unstable +#[target_feature(enable = "f")] +//~^ERROR: the target feature `f` is allowed in cfg but unstable otherwise +pub unsafe fn my_fun() {} diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr new file mode 100644 index 0000000000000..7f13c11798fcf --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-attribute-riscv.stderr @@ -0,0 +1,23 @@ +error[E0658]: the target feature `v` is currently unstable + --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:13:18 + | +LL | #[target_feature(enable = "v")] + | ^^^^^^^^^^^^ + | + = note: see issue #150257 for more information + = help: add `#![feature(riscv_target_feature)]` 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 target feature `f` is allowed in cfg but unstable otherwise + --> $DIR/cfg-stable-toggle-unstable-target-feature-attribute-riscv.rs:15:18 + | +LL | #[target_feature(enable = "f")] + | ^^^^^^^^^^^^ + | + = note: see issue #150257 for more information + = help: add `#![feature(riscv_target_feature)]` 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 2 previous errors + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs new file mode 100644 index 0000000000000..ab2b75ed5190f --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.rs @@ -0,0 +1,17 @@ +//! Ensure cfg-only stable target_features trigger warnings when enabled via compile flag. +//@ check-pass +//@ compile-flags: --crate-type=lib +//@ compile-flags: --target=riscv64gc-unknown-none-elf -Ctarget-feature=+v -Ctarget-feature=+f +// FIXME(#147881): *disable* the feature again for minicore as otherwise that will fail to build. +//@ minicore-compile-flags: -Ctarget-feature=-v -Ctarget-feature=-f +//@ needs-llvm-components: riscv +//@ ignore-backends: gcc +//@ add-minicore +#![feature(no_core)] +#![no_core] + +extern crate minicore; +use minicore::*; + +//~? WARN unstable feature specified for `-Ctarget-feature` +//~? WARN unstable feature specified for `-Ctarget-feature` diff --git a/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr new file mode 100644 index 0000000000000..b0167221aabaa --- /dev/null +++ b/tests/ui/target-feature/cfg-stable-toggle-unstable-target-feature-flag-enable-riscv.stderr @@ -0,0 +1,10 @@ +warning: unstable feature specified for `-Ctarget-feature`: `v` + | + = note: this feature is not stably supported; its behavior can change in the future + +warning: unstable feature specified for `-Ctarget-feature`: `f` + | + = note: this feature is allowed in cfg but unstable otherwise; its behavior can change in the future + +warning: 2 warnings emitted +