Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_codegen_ssa/src/target_features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,10 @@ pub fn internal_target_features<'a, const N: usize>(
} else {
sess.dcx().emit_warn(diag);
}
} else if stability.requires_nightly(/* in_cfg */ false).is_some() {
// An unstable feature. Warn about using it. It makes little sense
} else if stability.requires_nightly(/* in_cfg */ false).is_some()
&& !sess.is_nightly_build()
{
// An unstable feature. Warn about using it on stable. It makes little sense
// to hard-error here since we just warn about fully unknown
// features above.
let note = if stability.is_cfg_stable_toggle_unstable() {
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ impl EarlySession {
pub fn merge_functions(&self) -> MergeFunctions {
self.opts.unstable_opts.merge_functions.unwrap_or(self.target.merge_functions)
}

pub fn is_nightly_build(&self) -> bool {
self.opts.unstable_features.is_nightly_build()
}
}

/// Some info about the backend, returned by `CodegenBackend::init` and put into the `Session`.
Expand Down
13 changes: 4 additions & 9 deletions src/doc/rustc-dev-guide/src/tests/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@ This is a bootstrap/compiler implementation detail, but it can also be useful fo
This is useful because some behaviors of the compiler (e.g. diagnostics)
can differ depending on whether the compiler is nightly or not.

In `ui` tests and other test suites that support `//@ rustc-env`, you can specify

```rust,ignore
// Force unstable features to be usable on stable rustc
//@ rustc-env:RUSTC_BOOTSTRAP=1

// Or force nightly rustc to pretend it is a stable rustc
//@ rustc-env:RUSTC_BOOTSTRAP=-1

@RalfJung RalfJung Sep 28, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if rustc-env:RUSTC_BOOTSTRAP=1 ever makes sense in a ui test, but rustc-env:RUSTC_BOOTSTRAP=-1 definitely does not.
Cc @jieyouxu

View changes since the review

@jieyouxu jieyouxu Sep 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay so rustc-env:RUSTC_BOOTSTRAP=1 is also pointless. I'll remove the example then.

```
Note that setting `RUSTC_BOOTSTRAP` in ui tests (e.g. via `//@ rustc-env`) is pointless since ui
tests inherit the bootstrap env var from bootstrap (so it's set to `1` by default), and since
compiletest itself passes `-Z` flags (so `-1` breaks the test). To test stable-only behavior, you
need to write a `run-make` test instead.

For `run-make`/`run-make-cargo` tests, `//@ rustc-env` is not supported.
You can do something like the following for individual `rustc` invocations.
Expand Down
20 changes: 20 additions & 0 deletions tests/run-make/unstable-target-feature/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//@ only-x86_64
// FIXME: Once GCC backend is fixed, remove this `ignore-backends`.
//@ ignore-backends: gcc

// Ensure that on stable we don't suggest restricting with an unsafe trait and we continue

@Kobzol Kobzol Oct 23, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this comment mean? It feels like it's not relevant to the test at all.

(I'm porting this to be an UI test now in #164802)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, I probably accidentally copied this over from the run-make test I used as template...

I was not able to make this a UI test because it tests stable-only behavior. But maybe there's now a way to do that?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, since #163664. Thanks for confirming!

// mentioning the rest of the obligation chain.

use run_make_support::{diff, rustc};

fn main() {
let out = rustc()
.env("RUSTC_BOOTSTRAP", "-1")
.input("unstable-target-feature.rs")
.args(&["-Ctarget-feature=+x87", "--crate-type=rlib"])
.run()
.assert_stderr_not_contains("help: consider restricting type parameter `T`")
.assert_stderr_contains("unstable feature")
.stderr_utf8();
diff().expected_file("unstable-target-feature.stderr").actual_text("(stable rustc)", &out).run()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/// Tidy is unhappy if we leave the file empty.
pub fn empty() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
warning: unstable feature specified for `-Ctarget-feature`: `x87`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

warning: 1 warning emitted

12 changes: 3 additions & 9 deletions tests/ui/abi/riscv-discoverability-guidance.riscv32.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
warning: unstable feature specified for `-Ctarget-feature`: `unaligned-scalar-mem`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

error[E0703]: invalid ABI: found `riscv-interrupt`
--> $DIR/riscv-discoverability-guidance.rs:21:8
--> $DIR/riscv-discoverability-guidance.rs:16:8
|
LL | extern "riscv-interrupt" fn isr() {}
| ^^^^^^^^^^^^^^^^^ invalid ABI
Expand All @@ -17,7 +11,7 @@ LL | extern "riscv-interrupt-m" fn isr() {}
| ++

error[E0703]: invalid ABI: found `riscv-interrupt-u`
--> $DIR/riscv-discoverability-guidance.rs:26:8
--> $DIR/riscv-discoverability-guidance.rs:21:8
|
LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^ invalid ABI
Expand All @@ -29,6 +23,6 @@ LL - extern "riscv-interrupt-u" fn isr_U() {}
LL + extern "riscv-interrupt-m" fn isr_U() {}
|

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0703`.
12 changes: 3 additions & 9 deletions tests/ui/abi/riscv-discoverability-guidance.riscv64.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
warning: unstable feature specified for `-Ctarget-feature`: `unaligned-scalar-mem`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

error[E0703]: invalid ABI: found `riscv-interrupt`
--> $DIR/riscv-discoverability-guidance.rs:21:8
--> $DIR/riscv-discoverability-guidance.rs:16:8
|
LL | extern "riscv-interrupt" fn isr() {}
| ^^^^^^^^^^^^^^^^^ invalid ABI
Expand All @@ -17,7 +11,7 @@ LL | extern "riscv-interrupt-m" fn isr() {}
| ++

error[E0703]: invalid ABI: found `riscv-interrupt-u`
--> $DIR/riscv-discoverability-guidance.rs:26:8
--> $DIR/riscv-discoverability-guidance.rs:21:8
|
LL | extern "riscv-interrupt-u" fn isr_U() {}
| ^^^^^^^^^^^^^^^^^^^ invalid ABI
Expand All @@ -29,6 +23,6 @@ LL - extern "riscv-interrupt-u" fn isr_U() {}
LL + extern "riscv-interrupt-m" fn isr_U() {}
|

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0703`.
5 changes: 0 additions & 5 deletions tests/ui/abi/riscv-discoverability-guidance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
#![no_core]
#![feature(no_core, lang_items, abi_riscv_interrupt)]

//~? WARN unstable feature specified for `-Ctarget-feature`
//~? NOTE this feature is not stably supported; its behavior can change in the future
//~? NOTE previously accepted
//~? NOTE for more information, see issue

extern crate minicore;
use minicore::*;

Expand Down
1 change: 0 additions & 1 deletion tests/ui/abi/sparcv8plus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
//@[sparc_cpu_v9_feature_v8plus] needs-llvm-components: sparc
//@ ignore-backends: gcc

//[sparc_feature_v8plus,sparc_cpu_v9_feature_v8plus]~? WARN unstable feature specified for `-Ctarget-feature`
//[sparc_feature_v8plus,sparc_cpu_v9_feature_v8plus]~? WARN `v8plus` must be disabled

#![crate_type = "rlib"]
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/sparcv8plus.sparc.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: -v8plus,-v9
--> $DIR/sparcv8plus.rs:31:1
--> $DIR/sparcv8plus.rs:30:1
|
LL | compile_error!("-v8plus,-v9");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/abi/sparcv8plus.sparc_cpu_v9.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: -v8plus,+v9
--> $DIR/sparcv8plus.rs:44:1
--> $DIR/sparcv8plus.rs:43:1
|
LL | compile_error!("-v8plus,+v9");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 2 additions & 8 deletions tests/ui/abi/sparcv8plus.sparc_cpu_v9_feature_v8plus.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
warning: unstable feature specified for `-Ctarget-feature`: `v8plus`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

warning: target feature `v8plus` must be disabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

error: +v8plus,+v9
--> $DIR/sparcv8plus.rs:35:1
--> $DIR/sparcv8plus.rs:34:1
|
LL | compile_error!("+v8plus,+v9");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 2 warnings emitted
error: aborting due to 1 previous error; 1 warning emitted

10 changes: 2 additions & 8 deletions tests/ui/abi/sparcv8plus.sparc_feature_v8plus.stderr
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
warning: unstable feature specified for `-Ctarget-feature`: `v8plus`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

warning: target feature `v8plus` must be disabled to ensure that the ABI of the current target can be implemented correctly
|
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

error: +v8plus,-v9 (FIXME)
--> $DIR/sparcv8plus.rs:40:1
--> $DIR/sparcv8plus.rs:39:1
|
LL | compile_error!("+v8plus,-v9 (FIXME)");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error; 2 warnings emitted
error: aborting due to 1 previous error; 1 warning emitted

2 changes: 1 addition & 1 deletion tests/ui/abi/sparcv8plus.sparcv8plus.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: +v8plus,+v9
--> $DIR/sparcv8plus.rs:35:1
--> $DIR/sparcv8plus.rs:34:1
|
LL | compile_error!("+v8plus,+v9");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/asm/hexagon-register-pairs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#![crate_type = "lib"]
#![no_core]

//~? WARN unstable feature specified for `-Ctarget-feature`: `hvx-length128b`

extern crate minicore;
use minicore::*;

Expand Down
12 changes: 3 additions & 9 deletions tests/ui/asm/hexagon-register-pairs.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
warning: unstable feature specified for `-Ctarget-feature`: `hvx-length128b`
|
= note: this feature is not stably supported; its behavior can change in the future
= note: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #162235 <https://github.com/rust-lang/rust/issues/162235>

error: avoid using named labels in inline assembly
--> $DIR/hexagon-register-pairs.rs:32:15
--> $DIR/hexagon-register-pairs.rs:30:15
|
LL | asm!("label1: r7:6 = combine(#2, #3)");
| ^^^^^^
Expand All @@ -15,13 +9,13 @@ LL | asm!("label1: r7:6 = combine(#2, #3)");
= note: `#[deny(named_asm_labels)]` on by default

error: avoid using named labels in inline assembly
--> $DIR/hexagon-register-pairs.rs:35:15
--> $DIR/hexagon-register-pairs.rs:33:15
|
LL | asm!("hexagon_label: nop");
| ^^^^^^^^^^^^^
|
= help: only local labels of the form `<number>:` should be used in inline asm
= note: see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

2 changes: 0 additions & 2 deletions tests/ui/asm/hexagon/bad-reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
//@ needs-llvm-components: hexagon
//@ ignore-backends: gcc

//~? WARN unstable feature specified for `-Ctarget-feature`: `hvx-length128b`

#![crate_type = "lib"]
#![feature(no_core, asm_experimental_arch)]
#![no_core]
Expand Down
Loading
Loading