From 4dd862f2fed9db0e53ccecb42481ed4c579a2f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 2 Oct 2026 14:25:10 +0200 Subject: [PATCH 1/5] Add `RUSTC_BOOTSTRAP=-2` as a way of simulating a stable rustc in UI tests --- compiler/rustc_driver_impl/src/lib.rs | 2 +- compiler/rustc_feature/src/lib.rs | 36 +++++++++++++++++-- compiler/rustc_feature/src/tests.rs | 7 ++++ compiler/rustc_session/src/config.rs | 30 +++++++++------- src/doc/rustc-dev-guide/src/tests/misc.md | 27 ++++++-------- src/librustdoc/config.rs | 2 +- ..._bootstrap.force_stable_allow_flags.stderr | 9 +++++ tests/ui/bootstrap/rustc_bootstrap.rs | 10 ++++-- 8 files changed, 87 insertions(+), 36 deletions(-) create mode 100644 tests/ui/bootstrap/rustc_bootstrap.force_stable_allow_flags.stderr diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 1ba7ce953b5d4..c51ac912d455f 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -1303,7 +1303,7 @@ pub fn handle_help(matches: &getopts::Matches, args: &[String]) -> bool { let chelp_pos = opt_help_pos("C"); let print_help = || { // Only show unstable options in --help if we accept unstable options. - let unstable_enabled = nightly_options::is_unstable_enabled(&matches); + let unstable_enabled = nightly_options::unstable_options_enabled(&matches); let nightly_build = nightly_options::match_is_nightly_build(&matches); usage(matches.opt_present("verbose"), unstable_enabled, nightly_build); }; diff --git a/compiler/rustc_feature/src/lib.rs b/compiler/rustc_feature/src/lib.rs index 83bf4f47a8ac9..e2eadaa66b0f0 100644 --- a/compiler/rustc_feature/src/lib.rs +++ b/compiler/rustc_feature/src/lib.rs @@ -36,15 +36,34 @@ pub struct Feature { #[derive(Clone, Copy, Debug, Hash)] pub enum UnstableFeatures { - /// Disallow use of unstable features, as on beta/stable channels. + /// Disallow use of unstable features and unstable compiler flags. + /// + /// Used by default by beta/stable channels. Disallow, - /// Allow use of unstable features, as on nightly. + /// Allow use of unstable features and unstable compiler flags. + /// + /// Used by default by the nightly channel. Allow, + /// Allow use of unstable features and unstable compiler flags, even if it is not the default + /// behavior. + /// + /// Can be used to make a beta/stable channel act like a nightly channel. + /// /// Errors are bypassed for bootstrapping. This is required any time /// during the build that feature-related lints are set to warn or above /// because the build turns on warnings-as-errors and uses lots of unstable /// features. As a result, this is always required for building Rust itself. Cheat, + /// Allow the use of *unstable compiler flags*, but disallow the use of + /// *unstable language features*. + /// And in general, try to treat everything except for compiler flags as if we were on stable. + /// + /// **This mode is designed only for internal testing of rustc.** + /// + /// Specifically, we need it when we want to test how rustc behaves on the stable channel, + /// but at the same time we need to be able to pass it some unstable `-Z` compiler flags + /// required for the testing infrastructure itself to work. + ActAsStableForTesting, } impl UnstableFeatures { @@ -76,6 +95,8 @@ impl UnstableFeatures { // Hypnotize ourselves so that we think we are a stable compiler and thus don't // allow any unstable features. "-1" => return UnstableFeatures::Disallow, + // Act as stable, but still accept unstable compiler flags required by compiletest + "-2" => return UnstableFeatures::ActAsStableForTesting, _ => {} } } @@ -83,10 +104,19 @@ impl UnstableFeatures { if disable_unstable_features { UnstableFeatures::Disallow } else { UnstableFeatures::Allow } } + pub fn allow_unstable_compiler_flags(&self) -> bool { + match *self { + UnstableFeatures::Allow + | UnstableFeatures::Cheat + | UnstableFeatures::ActAsStableForTesting => true, + UnstableFeatures::Disallow => false, + } + } + pub fn is_nightly_build(&self) -> bool { match *self { UnstableFeatures::Allow | UnstableFeatures::Cheat => true, - UnstableFeatures::Disallow => false, + UnstableFeatures::Disallow | UnstableFeatures::ActAsStableForTesting => false, } } } diff --git a/compiler/rustc_feature/src/tests.rs b/compiler/rustc_feature/src/tests.rs index a5d589171d105..9280a9de7e506 100644 --- a/compiler/rustc_feature/src/tests.rs +++ b/compiler/rustc_feature/src/tests.rs @@ -34,4 +34,11 @@ fn rustc_bootstrap_parsing() { // Does not support specifying any crate. assert!(is_force_stable(Some("x"))); assert!(is_force_stable(Some("x,y,z"))); + + // `RUSTC_BOOTSTRAP=-2` simulates the stable toolchain, while allowing unstable compiler flags + // to be passed. + std::assert_matches!( + UnstableFeatures::from_environment_value(None, Ok("-2".to_string())), + UnstableFeatures::ActAsStableForTesting + ); } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index fdfc2aacc79a8..255e59caf2607 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2395,7 +2395,7 @@ pub fn parse_crate_edition( } }; - if !edition.is_stable() && !nightly_options::is_unstable_enabled(matches) { + if !edition.is_stable() && !nightly_options::unstable_options_enabled(matches) { let msg = if !is_nightly { format!( "the crate requires edition {edition}, but the latest edition supported by this \ @@ -2413,10 +2413,10 @@ pub fn parse_crate_edition( fn check_error_format_stability( early_dcx: &EarlyDiagCtxt, unstable_opts: &UnstableOptions, - is_nightly_build: bool, + unstable_flags_enabled: bool, format: ErrorOutputType, ) { - if unstable_opts.unstable_options || is_nightly_build { + if unstable_opts.unstable_options || unstable_flags_enabled { return; } let format = match format { @@ -2771,7 +2771,7 @@ pub fn build_session_options( check_error_format_stability( early_dcx, &unstable_opts, - unstable_features.is_nightly_build(), + unstable_features.allow_unstable_compiler_flags(), error_format, ); @@ -2867,7 +2867,7 @@ pub fn build_session_options( } } - let unstable_options_enabled = nightly_options::is_unstable_enabled(matches); + let unstable_options_enabled = nightly_options::unstable_options_enabled(matches); if !unstable_options_enabled && cg.force_frame_pointers == FramePointer::NonLeaf { early_dcx.early_fatal( "`-Cforce-frame-pointers=non-leaf` or `always` also requires `-Zunstable-options` \ @@ -2875,7 +2875,7 @@ pub fn build_session_options( ) } - if !nightly_options::is_unstable_enabled(matches) && !unstable_opts.offload.is_empty() { + if !unstable_options_enabled && !unstable_opts.offload.is_empty() { early_dcx.early_fatal( "`-Zoffload=Enable` also requires `-Zunstable-options` and a nightly compiler", ) @@ -3178,17 +3178,21 @@ pub mod nightly_options { use super::{OptionStability, RustcOptGroup}; use crate::EarlyDiagCtxt; - pub fn is_unstable_enabled(matches: &getopts::Matches) -> bool { - match_is_nightly_build(matches) + /// Are we allowed to use -Z compiler flags *and* -Zunstable-options was passed? + pub fn unstable_options_enabled(matches: &getopts::Matches) -> bool { + unstable_compiler_flags_allowed(matches) && matches.opt_strs("Z").iter().any(|x| *x == "unstable-options") } - pub fn match_is_nightly_build(matches: &getopts::Matches) -> bool { - is_nightly_build(matches.opt_str("crate-name").as_deref()) + /// Are we allowed to use -Z compiler flags? + pub fn unstable_compiler_flags_allowed(matches: &getopts::Matches) -> bool { + UnstableFeatures::from_environment(matches.opt_str("crate-name").as_deref()) + .allow_unstable_compiler_flags() } - fn is_nightly_build(krate: Option<&str>) -> bool { - UnstableFeatures::from_environment(krate).is_nightly_build() + pub fn match_is_nightly_build(matches: &getopts::Matches) -> bool { + let krate = matches.opt_str("crate-name"); + UnstableFeatures::from_environment(krate.as_deref()).is_nightly_build() } pub fn check_nightly_options( @@ -3197,7 +3201,7 @@ pub mod nightly_options { flags: &[RustcOptGroup], ) { let has_z_unstable_option = matches.opt_strs("Z").iter().any(|x| *x == "unstable-options"); - let really_allows_unstable_options = match_is_nightly_build(matches); + let really_allows_unstable_options = unstable_compiler_flags_allowed(matches); let mut nightly_options_on_stable = 0; for opt in flags.iter() { diff --git a/src/doc/rustc-dev-guide/src/tests/misc.md b/src/doc/rustc-dev-guide/src/tests/misc.md index 8fe49c82e9873..af60cd752e1f5 100644 --- a/src/doc/rustc-dev-guide/src/tests/misc.md +++ b/src/doc/rustc-dev-guide/src/tests/misc.md @@ -11,23 +11,18 @@ This is a bootstrap/compiler implementation detail, but it can also be useful fo compiler, even if it's actually a nightly `rustc`. This is useful because some behaviors of the compiler (e.g. diagnostics) can differ depending on whether the compiler is nightly or not. +- `RUSTC_BOOTSTRAP=-2` will force a given `rustc` to pretend it is a stable + compiler, even if it's actually a nightly `rustc`. + However, the compiler will still accept unstable compiler flags. + This is useful for internal testing of the compiler, where we need to pass + unstable flags required by compiletest, but we also want to test the compiler's + behavior on the stable channel. -Note that setting `RUSTC_BOOTSTRAP` in ui tests (e.g. via `//@ rustc-env`) is pointless since ui +Note that setting `RUSTC_BOOTSTRAP=-1` 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. +compiletest itself passes `-Z` flags (so `-1` breaks the test). To test stable-only behavior, use +`RUSTC_BOOTSTRAP=-2` instead. For `run-make`/`run-make-cargo` tests, `//@ rustc-env` is not supported. -You can do something like the following for individual `rustc` invocations. - -```rust,ignore -use run_make_support::rustc; - -fn main() { - rustc() - // Pretend that I am very stable - .env("RUSTC_BOOTSTRAP", "-1") - //... - .run(); -} -``` +You can do use the `run_make_support::stable_bare_rustc` function to create an instance of the compiler +that acts as the stable channel (this internally uses `RUSTC_BOOTSTRAP=-1`). diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 170352dabf656..f5ed0467fa5a6 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -450,7 +450,7 @@ impl Options { match ( output_format_s.as_ref().map(|_| output_format), show_coverage, - nightly_options::is_unstable_enabled(matches), + nightly_options::unstable_options_enabled(matches), ) { (None | Some(OutputFormat::CoverageJson), true, _) => {} (_, true, _) => { diff --git a/tests/ui/bootstrap/rustc_bootstrap.force_stable_allow_flags.stderr b/tests/ui/bootstrap/rustc_bootstrap.force_stable_allow_flags.stderr new file mode 100644 index 0000000000000..c4436ca5a1815 --- /dev/null +++ b/tests/ui/bootstrap/rustc_bootstrap.force_stable_allow_flags.stderr @@ -0,0 +1,9 @@ +error[E0554]: `#![feature]` may not be used on the nightly release channel + --> $DIR/rustc_bootstrap.rs:51:1 + | +LL | #![feature(rustc_attrs)] + | ^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0554`. diff --git a/tests/ui/bootstrap/rustc_bootstrap.rs b/tests/ui/bootstrap/rustc_bootstrap.rs index fb72bba95a158..96a464e8e4dbe 100644 --- a/tests/ui/bootstrap/rustc_bootstrap.rs +++ b/tests/ui/bootstrap/rustc_bootstrap.rs @@ -6,11 +6,13 @@ //! - `1`: cheat, allow usage of unstable features even if rustc thinks it is a stable compiler. //! - `x,y,z`: comma-delimited list of crates. //! - `-1`: force rustc to think it is a stable compiler. +//! - `-2`: force rustc to think it is a stable compiler, while still allowing -Z flags. // ignore-tidy-linelength -//@ revisions: default_nightly cheat cheat_single_crate cheat_multi_crate force_stable invalid_zero invalid_junk +//@ revisions: default_nightly cheat cheat_single_crate cheat_multi_crate force_stable force_stable_allow_flags invalid_zero invalid_junk //@ only-nightly +//@ normalize-stderr: "dev release channel" -> "nightly release channel" //@[default_nightly] unset-rustc-env:RUSTC_BOOTSTRAP //@[default_nightly] check-pass @@ -39,10 +41,14 @@ //@[force_stable] rustc-env:RUSTC_BOOTSTRAP=-1 //@[force_stable] compile-flags: -Z unstable-options -#![crate_type = "lib"] +// Here rustc shouldn't complain about compiletest's -Z flags being passed. +//@[force_stable_allow_flags] rustc-env:RUSTC_BOOTSTRAP=-2 +//@[force_stable_allow_flags] compile-flags: -Z unstable-options +#![crate_type = "lib"] // Note: `rustc_attrs` is a perma-unstable internal feature that is unlikely to change, which is // used as a proxy to check `RUSTC_BOOTSTRAP` versus stability checking logic. #![feature(rustc_attrs)] +//[force_stable_allow_flags]~^ ERROR: `#![feature]` may not be used on the //[force_stable]~? RAW the option `Z` is only accepted on the nightly compiler From ee1cbd6d2bdaf60f12a18d08f109339d61e47bb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 2 Oct 2026 16:12:41 +0200 Subject: [PATCH 2/5] Implement `act-as-stable` compiletest directive --- src/doc/rustc-dev-guide/src/tests/misc.md | 14 ++++++++++---- src/tools/compiletest/src/directives.rs | 1 + .../compiletest/src/directives/directive_names.rs | 1 + src/tools/compiletest/src/directives/handlers.rs | 6 ++++++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/doc/rustc-dev-guide/src/tests/misc.md b/src/doc/rustc-dev-guide/src/tests/misc.md index af60cd752e1f5..6a4042208bef8 100644 --- a/src/doc/rustc-dev-guide/src/tests/misc.md +++ b/src/doc/rustc-dev-guide/src/tests/misc.md @@ -18,11 +18,17 @@ This is a bootstrap/compiler implementation detail, but it can also be useful fo unstable flags required by compiletest, but we also want to test the compiler's behavior on the stable channel. +### UI tests + Note that setting `RUSTC_BOOTSTRAP=-1` 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, use -`RUSTC_BOOTSTRAP=-2` instead. +compiletest itself passes `-Z` flags (so `-1` breaks the test). + +To test stable-only behavior, use the `act-as-stable` directive, which will set `RUSTC_BOOTSTRAP=-2` +for you. + +### Run-make tests -For `run-make`/`run-make-cargo` tests, `//@ rustc-env` is not supported. -You can do use the `run_make_support::stable_bare_rustc` function to create an instance of the compiler +For `run-make`/`run-make-cargo` tests, `//@ act-as-stable` is not supported. +You can use the `run_make_support::stable_bare_rustc` function to create an instance of the compiler that acts as the stable channel (this internally uses `RUSTC_BOOTSTRAP=-1`). diff --git a/src/tools/compiletest/src/directives.rs b/src/tools/compiletest/src/directives.rs index 1037b2c6375b7..4ef2b5fd46d65 100644 --- a/src/tools/compiletest/src/directives.rs +++ b/src/tools/compiletest/src/directives.rs @@ -222,6 +222,7 @@ pub(crate) struct TestProps { } mod directives { + pub(crate) const ACT_AS_STABLE: &str = "act-as-stable"; pub(crate) const ERROR_PATTERN: &str = "error-pattern"; pub(crate) const REGEX_ERROR_PATTERN: &str = "regex-error-pattern"; pub(crate) const COMPILE_FLAGS: &str = "compile-flags"; diff --git a/src/tools/compiletest/src/directives/directive_names.rs b/src/tools/compiletest/src/directives/directive_names.rs index 732f4ab275dd7..07ac09944379b 100644 --- a/src/tools/compiletest/src/directives/directive_names.rs +++ b/src/tools/compiletest/src/directives/directive_names.rs @@ -9,6 +9,7 @@ pub(crate) static KNOWN_DIRECTIVE_NAMES_SET: LazyLock> = /// a best-effort approximation for diagnostics. Add new directives to this list when needed. pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[ // tidy-alphabetical-start + "act-as-stable", "add-minicore", "assembly-output", "aux-bin", diff --git a/src/tools/compiletest/src/directives/handlers.rs b/src/tools/compiletest/src/directives/handlers.rs index 4e86dcb308f0d..f33688180419f 100644 --- a/src/tools/compiletest/src/directives/handlers.rs +++ b/src/tools/compiletest/src/directives/handlers.rs @@ -64,6 +64,12 @@ fn make_directive_handlers_map() -> HashMap<&'static str, Handler> { // these handlers, e.g. by getting rid of now-redundant name checks. let handlers: Vec = vec![ + handler(ACT_AS_STABLE, |_config, ln, props| { + if ln.name == ACT_AS_STABLE { + // Simulate the stable toolchain, but allow unstable -Z flags passed by compiletest + props.rustc_env.push(("RUSTC_BOOTSTRAP".to_string(), "-2".to_string())); + } + }), handler(ERROR_PATTERN, |config, ln, props| { config.push_name_value_directive(ln, ERROR_PATTERN, &mut props.error_patterns, |r| r); }), From aba8f2ecf7503c35f947994a2e6e3195371a2fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 2 Oct 2026 16:12:54 +0200 Subject: [PATCH 3/5] Use `act-as-stable` in the `feature-gate-autodiff-use` test --- ... feature-gate-autodiff-use.nightly.stderr} | 4 ++-- .../feature-gate-autodiff-use.rs | 22 ++++++++++++------- .../feature-gate-autodiff-use.stable.stderr | 19 ++++++++++++++++ 3 files changed, 35 insertions(+), 10 deletions(-) rename tests/ui/feature-gates/{feature-gate-autodiff-use.stderr => feature-gate-autodiff-use.nightly.stderr} (91%) create mode 100644 tests/ui/feature-gates/feature-gate-autodiff-use.stable.stderr diff --git a/tests/ui/feature-gates/feature-gate-autodiff-use.stderr b/tests/ui/feature-gates/feature-gate-autodiff-use.nightly.stderr similarity index 91% rename from tests/ui/feature-gates/feature-gate-autodiff-use.stderr rename to tests/ui/feature-gates/feature-gate-autodiff-use.nightly.stderr index 94b9a065e491e..ca724632063d4 100644 --- a/tests/ui/feature-gates/feature-gate-autodiff-use.stderr +++ b/tests/ui/feature-gates/feature-gate-autodiff-use.nightly.stderr @@ -1,5 +1,5 @@ error[E0658]: use of unstable library feature `autodiff` - --> $DIR/feature-gate-autodiff-use.rs:11:3 + --> $DIR/feature-gate-autodiff-use.rs:16:3 | LL | #[autodiff_reverse(dfoo)] | ^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | #[autodiff_reverse(dfoo)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: use of unstable library feature `autodiff` - --> $DIR/feature-gate-autodiff-use.rs:5:5 + --> $DIR/feature-gate-autodiff-use.rs:9:5 | LL | use std::autodiff::autodiff_reverse; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/feature-gates/feature-gate-autodiff-use.rs b/tests/ui/feature-gates/feature-gate-autodiff-use.rs index 85608be4ac04a..d7336e50df1f3 100644 --- a/tests/ui/feature-gates/feature-gate-autodiff-use.rs +++ b/tests/ui/feature-gates/feature-gate-autodiff-use.rs @@ -1,16 +1,22 @@ +//@ revisions: nightly stable +//@[nightly] only-nightly +//@[stable] act-as-stable + // This checks that without enabling the autodiff feature, we can't import std::autodiff::autodiff; #![crate_type = "lib"] use std::autodiff::autodiff_reverse; -//~^ ERROR use of unstable library feature `autodiff` -//| NOTE see issue #124509 for more information -//| HELP add `#![feature(autodiff)]` to the crate attributes to enable -//| NOTE this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +//[stable]~^ ERROR use of unstable library feature `autodiff` +//[nightly]~^^ ERROR use of unstable library feature `autodiff` +//[nightly]~| NOTE see issue #124509 for more information +//[nightly]~| HELP add `#![feature(autodiff)]` to the crate attributes to enable +//[nightly]~| NOTE this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date #[autodiff_reverse(dfoo)] -//~^ ERROR use of unstable library feature `autodiff` [E0658] -//| NOTE see issue #124509 for more information -//| HELP add `#![feature(autodiff)]` to the crate attributes to enable -//| NOTE this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date +//[stable]~^ ERROR use of unstable library feature `autodiff` [E0658] +//[nightly]~^^ ERROR use of unstable library feature `autodiff` [E0658] +//[nightly]~| NOTE see issue #124509 for more information +//[nightly]~| HELP add `#![feature(autodiff)]` to the crate attributes to enable +//[nightly]~| NOTE this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date fn foo() {} diff --git a/tests/ui/feature-gates/feature-gate-autodiff-use.stable.stderr b/tests/ui/feature-gates/feature-gate-autodiff-use.stable.stderr new file mode 100644 index 0000000000000..2ac3c82b644ef --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-autodiff-use.stable.stderr @@ -0,0 +1,19 @@ +error[E0658]: use of unstable library feature `autodiff` + --> $DIR/feature-gate-autodiff-use.rs:16:3 + | +LL | #[autodiff_reverse(dfoo)] + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #124509 for more information + +error[E0658]: use of unstable library feature `autodiff` + --> $DIR/feature-gate-autodiff-use.rs:9:5 + | +LL | use std::autodiff::autodiff_reverse; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #124509 for more information + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0658`. From 3caf4df9b7d374f09e4f1ab4bebce406d264bab3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 2 Oct 2026 16:20:04 +0200 Subject: [PATCH 4/5] Migrate `const-destruct-stable-toolchain` from a run-make test to a UI test --- .../const-drop-stable.stderr | 11 -------- .../const-drop.rs | 3 -- .../const-destruct-stable-toolchain/rmake.rs | 28 ------------------- ...-destruct-stable-toolchain.nightly.stderr} | 2 +- .../consts/const-destruct-stable-toolchain.rs | 15 ++++++++++ ...st-destruct-stable-toolchain.stable.stderr | 11 ++++++++ 6 files changed, 27 insertions(+), 43 deletions(-) delete mode 100644 tests/run-make/const-destruct-stable-toolchain/const-drop-stable.stderr delete mode 100644 tests/run-make/const-destruct-stable-toolchain/const-drop.rs delete mode 100644 tests/run-make/const-destruct-stable-toolchain/rmake.rs rename tests/{run-make/const-destruct-stable-toolchain/const-drop-nightly.stderr => ui/consts/const-destruct-stable-toolchain.nightly.stderr} (91%) create mode 100644 tests/ui/consts/const-destruct-stable-toolchain.rs create mode 100644 tests/ui/consts/const-destruct-stable-toolchain.stable.stderr diff --git a/tests/run-make/const-destruct-stable-toolchain/const-drop-stable.stderr b/tests/run-make/const-destruct-stable-toolchain/const-drop-stable.stderr deleted file mode 100644 index dc37d840658fd..0000000000000 --- a/tests/run-make/const-destruct-stable-toolchain/const-drop-stable.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> const-drop.rs:1:24 - | -1 | const fn const_drop(_: T) {} - | ^ - value is dropped here - | | - | the destructor for this type cannot be evaluated in constant functions - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0493`. diff --git a/tests/run-make/const-destruct-stable-toolchain/const-drop.rs b/tests/run-make/const-destruct-stable-toolchain/const-drop.rs deleted file mode 100644 index 6479498281fe5..0000000000000 --- a/tests/run-make/const-destruct-stable-toolchain/const-drop.rs +++ /dev/null @@ -1,3 +0,0 @@ -const fn const_drop(_: T) {} - -fn main() {} diff --git a/tests/run-make/const-destruct-stable-toolchain/rmake.rs b/tests/run-make/const-destruct-stable-toolchain/rmake.rs deleted file mode 100644 index 47d66cf267ab9..0000000000000 --- a/tests/run-make/const-destruct-stable-toolchain/rmake.rs +++ /dev/null @@ -1,28 +0,0 @@ -//@ needs-target-std -//@ ignore-backends: gcc - -// Test that the suggestion to constrain a type parameter that is dropped in a const -// function with a `[const] Destruct` bound is only offered on nightly, since the bound -// requires an unstable feature. - -use run_make_support::{diff, rustc, stable_bare_rustc}; - -fn main() { - let out = stable_bare_rustc() - .input("const-drop.rs") - .edition("2015") - .run_fail() - .assert_stderr_not_contains("consider restricting type parameter `T`") - .stderr_utf8(); - diff().expected_file("const-drop-stable.stderr").actual_text("(rustc)", &out).run(); - let out = rustc() - .input("const-drop.rs") - .edition("2015") - .ui_testing() - .run_fail() - .assert_stderr_contains( - "consider restricting type parameter `T` with unstable trait `Destruct`", - ) - .stderr_utf8(); - diff().expected_file("const-drop-nightly.stderr").actual_text("(rustc)", &out).run(); -} diff --git a/tests/run-make/const-destruct-stable-toolchain/const-drop-nightly.stderr b/tests/ui/consts/const-destruct-stable-toolchain.nightly.stderr similarity index 91% rename from tests/run-make/const-destruct-stable-toolchain/const-drop-nightly.stderr rename to tests/ui/consts/const-destruct-stable-toolchain.nightly.stderr index 52f68743b6275..2d05a300165aa 100644 --- a/tests/run-make/const-destruct-stable-toolchain/const-drop-nightly.stderr +++ b/tests/ui/consts/const-destruct-stable-toolchain.nightly.stderr @@ -1,5 +1,5 @@ error[E0493]: destructor of `T` cannot be evaluated at compile-time - --> const-drop.rs:1:24 + --> $DIR/const-destruct-stable-toolchain.rs:12:24 | LL | const fn const_drop(_: T) {} | ^ - value is dropped here diff --git a/tests/ui/consts/const-destruct-stable-toolchain.rs b/tests/ui/consts/const-destruct-stable-toolchain.rs new file mode 100644 index 0000000000000..ad16a74508e4c --- /dev/null +++ b/tests/ui/consts/const-destruct-stable-toolchain.rs @@ -0,0 +1,15 @@ +// Test that the suggestion to constrain a type parameter that is dropped in a const +// function with a `[const] Destruct` bound is only offered on nightly, since the bound +// requires an unstable feature. +// +//@ needs-target-std +//@ ignore-backends: gcc +// +//@ revisions: stable nightly +// +//@[stable] act-as-stable +//@[nightly] only-nightly +const fn const_drop(_: T) {} +//~^ ERROR: destructor of `T` cannot be evaluated at compile-time [E0493] + +fn main() {} diff --git a/tests/ui/consts/const-destruct-stable-toolchain.stable.stderr b/tests/ui/consts/const-destruct-stable-toolchain.stable.stderr new file mode 100644 index 0000000000000..4755afcd3f1e3 --- /dev/null +++ b/tests/ui/consts/const-destruct-stable-toolchain.stable.stderr @@ -0,0 +1,11 @@ +error[E0493]: destructor of `T` cannot be evaluated at compile-time + --> $DIR/const-destruct-stable-toolchain.rs:12:24 + | +LL | const fn const_drop(_: T) {} + | ^ - value is dropped here + | | + | the destructor for this type cannot be evaluated in constant functions + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0493`. From 8e072e850460430833453017222e5a1d20ea7f1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Fri, 2 Oct 2026 16:25:27 +0200 Subject: [PATCH 5/5] Migrate `print-request-help-stable-unstable` from a run-make test to a UI test --- .../help-diff.diff | 7 ---- .../rmake.rs | 33 ------------------- ...quest-help-stable-unstable.nightly.stderr} | 0 .../print-request-help-stable-unstable.rs | 12 +++++++ ...equest-help-stable-unstable.stable.stderr} | 0 5 files changed, 12 insertions(+), 40 deletions(-) delete mode 100644 tests/run-make/print-request-help-stable-unstable/help-diff.diff delete mode 100644 tests/run-make/print-request-help-stable-unstable/rmake.rs rename tests/{run-make/print-request-help-stable-unstable/unstable-invalid-print-request-help.err => ui/compile-flags/print-request-help-stable-unstable.nightly.stderr} (100%) create mode 100644 tests/ui/compile-flags/print-request-help-stable-unstable.rs rename tests/{run-make/print-request-help-stable-unstable/stable-invalid-print-request-help.err => ui/compile-flags/print-request-help-stable-unstable.stable.stderr} (100%) diff --git a/tests/run-make/print-request-help-stable-unstable/help-diff.diff b/tests/run-make/print-request-help-stable-unstable/help-diff.diff deleted file mode 100644 index 8a9c3d0cf46c1..0000000000000 --- a/tests/run-make/print-request-help-stable-unstable/help-diff.diff +++ /dev/null @@ -1,7 +0,0 @@ -@@ -1,5 +1,5 @@ - error: unknown print request: `xxx` - | -- = help: valid print requests are: `calling-conventions`, `cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `tls-models` -+ = help: valid print requests are: `all-target-specs-json`, `backend-has-mnemonic`, `backend-has-zstd`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `target-spec-json-schema`, `tls-models`, `wasm-proc-macro-tuple` - = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information - diff --git a/tests/run-make/print-request-help-stable-unstable/rmake.rs b/tests/run-make/print-request-help-stable-unstable/rmake.rs deleted file mode 100644 index 49df84b353cd4..0000000000000 --- a/tests/run-make/print-request-help-stable-unstable/rmake.rs +++ /dev/null @@ -1,33 +0,0 @@ -//! Check that unstable print requests are omitted from help if compiler is in stable channel. -//! -//! Issue: - -//@ ignore-backends: gcc - -use run_make_support::{diff, rustc, similar, stable_bare_rustc}; - -fn main() { - let stable_invalid_print_request_help = - stable_bare_rustc().edition("2015").print("xxx").run_fail().stderr_utf8(); - assert!(!stable_invalid_print_request_help.contains("all-target-specs-json")); - diff() - .expected_file("stable-invalid-print-request-help.err") - .actual_text("stable_invalid_print_request_help", &stable_invalid_print_request_help) - .run(); - - let unstable_invalid_print_request_help = - rustc().edition("2015").print("xxx").run_fail().stderr_utf8(); - assert!(unstable_invalid_print_request_help.contains("all-target-specs-json")); - diff() - .expected_file("unstable-invalid-print-request-help.err") - .actual_text("unstable_invalid_print_request_help", &unstable_invalid_print_request_help) - .run(); - - let help_diff = similar::TextDiff::from_lines( - &stable_invalid_print_request_help, - &unstable_invalid_print_request_help, - ) - .unified_diff() - .to_string(); - diff().expected_file("help-diff.diff").actual_text("help_diff", help_diff).run(); -} diff --git a/tests/run-make/print-request-help-stable-unstable/unstable-invalid-print-request-help.err b/tests/ui/compile-flags/print-request-help-stable-unstable.nightly.stderr similarity index 100% rename from tests/run-make/print-request-help-stable-unstable/unstable-invalid-print-request-help.err rename to tests/ui/compile-flags/print-request-help-stable-unstable.nightly.stderr diff --git a/tests/ui/compile-flags/print-request-help-stable-unstable.rs b/tests/ui/compile-flags/print-request-help-stable-unstable.rs new file mode 100644 index 0000000000000..f75996f28e6bd --- /dev/null +++ b/tests/ui/compile-flags/print-request-help-stable-unstable.rs @@ -0,0 +1,12 @@ +//! Check that unstable print requests are omitted from help if compiler is in stable channel. +//! +//! Issue: + +//@ ignore-backends: gcc +//@ compile-flags: --print xxx +// +//@ revisions: stable nightly +//@[stable] act-as-stable +//@[nightly] only-nightly + +//~? ERROR unknown print request: `xxx` diff --git a/tests/run-make/print-request-help-stable-unstable/stable-invalid-print-request-help.err b/tests/ui/compile-flags/print-request-help-stable-unstable.stable.stderr similarity index 100% rename from tests/run-make/print-request-help-stable-unstable/stable-invalid-print-request-help.err rename to tests/ui/compile-flags/print-request-help-stable-unstable.stable.stderr