Repository navigation
Add new RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags mode for testing stable compiler behavior in UI tests
#163664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
8240628
94a6b12
522200b
aa97b1b
0c3b3be
f6c3d62
adbf2a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2411,7 +2411,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) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: grepping shows that there's still a reference to |
||
| let msg = if !is_nightly { | ||
| format!( | ||
| "the crate requires edition {edition}, but the latest edition supported by this \ | ||
|
|
@@ -2429,10 +2429,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 { | ||
|
|
@@ -2792,7 +2792,7 @@ pub fn build_session_options( | |
| check_error_format_stability( | ||
| early_dcx, | ||
| &unstable_opts, | ||
| unstable_features.is_nightly_build(), | ||
| unstable_features.allow_unstable_compiler_flag("error-format"), | ||
| error_format, | ||
| ); | ||
|
|
||
|
|
@@ -2888,15 +2888,15 @@ 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` \ | ||
| and a nightly compiler", | ||
| ) | ||
| } | ||
|
|
||
| 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", | ||
| ) | ||
|
|
@@ -2974,7 +2974,7 @@ pub fn build_session_options( | |
| } | ||
|
|
||
| // Parse any `-l` flags, which link to native libraries. | ||
| let libs = parse_native_libs(early_dcx, &unstable_opts, unstable_features, matches); | ||
| let libs = parse_native_libs(early_dcx, &unstable_opts, &unstable_features, matches); | ||
|
|
||
| let test = matches.opt_present("test"); | ||
|
|
||
|
|
@@ -3199,17 +3199,17 @@ 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 { | ||
| let unstable_features = | ||
| UnstableFeatures::from_environment(matches.opt_str("crate-name").as_deref()); | ||
| unstable_features.allow_unstable_compiler_flag("unstable-options") | ||
| && 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()) | ||
| } | ||
|
|
||
| fn is_nightly_build(krate: Option<&str>) -> bool { | ||
| UnstableFeatures::from_environment(krate).is_nightly_build() | ||
| let krate = matches.opt_str("crate-name"); | ||
| UnstableFeatures::from_environment(krate.as_deref()).is_nightly_build() | ||
| } | ||
|
|
||
| pub fn check_nightly_options( | ||
|
|
@@ -3218,7 +3218,8 @@ 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 unstable_features = | ||
| UnstableFeatures::from_environment(matches.opt_str("crate-name").as_deref()); | ||
| let mut nightly_options_on_stable = 0; | ||
|
|
||
| for opt in flags.iter() { | ||
|
|
@@ -3235,7 +3236,40 @@ pub mod nightly_options { | |
| opt.name | ||
| )); | ||
| } | ||
| if really_allows_unstable_options { | ||
|
|
||
| // Check if the matched values are enabled | ||
| // If we're dealing with -Z, then check all the matched values (i.e. -Zfoo, -Zbar, etc.) | ||
| // If we're dealing with other flags, check their name directly | ||
| if opt.name == "Z" { | ||
| // For `-Zui-testing -Zfoo=bar -Zfoo=baz`, this returns | ||
| // ["ui-testing", "foo=bar", "foo=baz"]. | ||
| // Check that all of them are allowed | ||
| let values = matches.opt_strs(opt.name); | ||
| let disallowed_flags = values | ||
| .iter() | ||
| .map(|flag| flag.split_once("=").map(|s| s.0).unwrap_or(flag)) | ||
| .filter(|flag| !unstable_features.allow_unstable_compiler_flag(flag)) | ||
| .collect::<Vec<_>>(); | ||
| if disallowed_flags.is_empty() { | ||
| continue; | ||
| } | ||
|
|
||
| // At this point, check if we're using the "allow unstable flags only" mode. | ||
| // In this case, if the user allowed only foo and bar, but then -Zbaz was also | ||
| // passed, rustc would only print that `-Z` is not allowed, which doesn't tell the | ||
| // user the actual -Z flag value that was disallowed. So we try to provide better | ||
| // diagnostics here (solely for the use-case of debugging compiletest itself). | ||
| let unstable_features = | ||
| UnstableFeatures::from_environment(matches.opt_str("crate-name").as_deref()); | ||
| if matches!( | ||
| unstable_features, | ||
| UnstableFeatures::AllowUnstableCompilerFlagsOnly { .. } | ||
| ) { | ||
| for flag in disallowed_flags { | ||
| let _ = early_dcx.early_err(format!("the -Z{flag} option was not allowed through `-allow-unstable-compiler-flags`")); | ||
| } | ||
| } | ||
| } else if unstable_features.allow_unstable_compiler_flag(opt.name) { | ||
| continue; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ pub(crate) static KNOWN_DIRECTIVE_NAMES_SET: LazyLock<HashSet<&str>> = | |
| /// 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", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I don't love the name, because it's actually more like There's candidates like
Maybe |
||
| "add-minicore", | ||
| "assembly-output", | ||
| "aux-bin", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually changing the help output, I wouldn't expect the "act-as-stable" mode to do that.
FWIW, I like the "less principled escape hatch" alternative better.
Accepting all unstable flags deviates too much from acting as stable, and we don't actually need all unstable flags for UI testing, only like 2-3 of them.
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, if we are able to limit it to only for-testing ones, that seems generally better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also thinking about that. Maybe we could do
RUSTC_BOOTSTRAP=-allow-unstable-compiler-flags=ui-testing,second-flag-that-compiletest-needs, etc.? One issue with that is that compiletest actually passes also-Zunstable-options, IIRC, which increases the blast radius of the "stable-like" behavior that we change in those tests.