Skip to content

Commit 4616c05

Browse files
Rollup merge of rust-lang#133159 - Zalathar:unstable-options-no-value, r=jieyouxu
Don't allow `-Zunstable-options` to take a value Passing an explicit boolean value (`-Zunstable-options=on`, `off` etc.) sometimes appears to work, but actually puts the compiler into an unintended state where unstable _options_ are still forbidden, but unstable values of _some_ stable options are allowed. This is a result of `-Zunstable-options` being checked in multiple different places, in slightly different ways. Fixing the checks in `config::nightly_options` to understand boolean values would be non-trivial, so for now it's easier to make things consistent by forbidding values in the `-Z` parser. --- There were a few uses of this in tests, which happened to work because they were tests of unstable values.
2 parents ad63143 + 660246b commit 4616c05

File tree

8 files changed

+36
-26
lines changed

8 files changed

+36
-26
lines changed

Diff for: compiler/rustc_session/src/options.rs

+29-19
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ fn build_options<O: Default>(
358358

359359
#[allow(non_upper_case_globals)]
360360
mod desc {
361-
pub(crate) const parse_no_flag: &str = "no value";
361+
pub(crate) const parse_no_value: &str = "no value";
362362
pub(crate) const parse_bool: &str =
363363
"one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false`";
364364
pub(crate) const parse_opt_bool: &str = parse_bool;
@@ -462,14 +462,18 @@ pub mod parse {
462462
pub(crate) use super::*;
463463
pub(crate) const MAX_THREADS_CAP: usize = 256;
464464

465-
/// This is for boolean options that don't take a value and start with
466-
/// `no-`. This style of option is deprecated.
467-
pub(crate) fn parse_no_flag(slot: &mut bool, v: Option<&str>) -> bool {
465+
/// This is for boolean options that don't take a value, and are true simply
466+
/// by existing on the command-line.
467+
///
468+
/// This style of option is deprecated, and is mainly used by old options
469+
/// beginning with `no-`.
470+
pub(crate) fn parse_no_value(slot: &mut bool, v: Option<&str>) -> bool {
468471
match v {
469472
None => {
470473
*slot = true;
471474
true
472475
}
476+
// Trying to specify a value is always forbidden.
473477
Some(_) => false,
474478
}
475479
}
@@ -1609,16 +1613,16 @@ options! {
16091613
"perform LLVM link-time optimizations"),
16101614
metadata: Vec<String> = (Vec::new(), parse_list, [TRACKED],
16111615
"metadata to mangle symbol names with"),
1612-
no_prepopulate_passes: bool = (false, parse_no_flag, [TRACKED],
1616+
no_prepopulate_passes: bool = (false, parse_no_value, [TRACKED],
16131617
"give an empty list of passes to the pass manager"),
16141618
no_redzone: Option<bool> = (None, parse_opt_bool, [TRACKED],
16151619
"disable the use of the redzone"),
16161620
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
1617-
no_stack_check: bool = (false, parse_no_flag, [UNTRACKED],
1621+
no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
16181622
"this option is deprecated and does nothing"),
1619-
no_vectorize_loops: bool = (false, parse_no_flag, [TRACKED],
1623+
no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
16201624
"disable loop vectorization optimization passes"),
1621-
no_vectorize_slp: bool = (false, parse_no_flag, [TRACKED],
1625+
no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],
16221626
"disable LLVM's SLP vectorization pass"),
16231627
opt_level: String = ("0".to_string(), parse_string, [TRACKED],
16241628
"optimization level (0-3, s, or z; default: 0)"),
@@ -1915,25 +1919,25 @@ options! {
19151919
"dump facts from NLL analysis into side files (default: no)"),
19161920
nll_facts_dir: String = ("nll-facts".to_string(), parse_string, [UNTRACKED],
19171921
"the directory the NLL facts are dumped into (default: `nll-facts`)"),
1918-
no_analysis: bool = (false, parse_no_flag, [UNTRACKED],
1922+
no_analysis: bool = (false, parse_no_value, [UNTRACKED],
19191923
"parse and expand the source, but run no analysis"),
1920-
no_codegen: bool = (false, parse_no_flag, [TRACKED_NO_CRATE_HASH],
1924+
no_codegen: bool = (false, parse_no_value, [TRACKED_NO_CRATE_HASH],
19211925
"run all passes except codegen; no output"),
1922-
no_generate_arange_section: bool = (false, parse_no_flag, [TRACKED],
1926+
no_generate_arange_section: bool = (false, parse_no_value, [TRACKED],
19231927
"omit DWARF address ranges that give faster lookups"),
19241928
no_implied_bounds_compat: bool = (false, parse_bool, [TRACKED],
19251929
"disable the compatibility version of the `implied_bounds_ty` query"),
1926-
no_jump_tables: bool = (false, parse_no_flag, [TRACKED],
1930+
no_jump_tables: bool = (false, parse_no_value, [TRACKED],
19271931
"disable the jump tables and lookup tables that can be generated from a switch case lowering"),
1928-
no_leak_check: bool = (false, parse_no_flag, [UNTRACKED],
1932+
no_leak_check: bool = (false, parse_no_value, [UNTRACKED],
19291933
"disable the 'leak check' for subtyping; unsound, but useful for tests"),
1930-
no_link: bool = (false, parse_no_flag, [TRACKED],
1934+
no_link: bool = (false, parse_no_value, [TRACKED],
19311935
"compile without linking"),
1932-
no_parallel_backend: bool = (false, parse_no_flag, [UNTRACKED],
1936+
no_parallel_backend: bool = (false, parse_no_value, [UNTRACKED],
19331937
"run LLVM in non-parallel mode (while keeping codegen-units and ThinLTO)"),
1934-
no_profiler_runtime: bool = (false, parse_no_flag, [TRACKED],
1938+
no_profiler_runtime: bool = (false, parse_no_value, [TRACKED],
19351939
"prevent automatic injection of the profiler_builtins crate"),
1936-
no_trait_vptr: bool = (false, parse_no_flag, [TRACKED],
1940+
no_trait_vptr: bool = (false, parse_no_value, [TRACKED],
19371941
"disable generation of trait vptr in vtable for upcasting"),
19381942
no_unique_section_names: bool = (false, parse_bool, [TRACKED],
19391943
"do not use unique names for text and data sections when -Z function-sections is used"),
@@ -1991,7 +1995,7 @@ options! {
19911995
proc_macro_execution_strategy: ProcMacroExecutionStrategy = (ProcMacroExecutionStrategy::SameThread,
19921996
parse_proc_macro_execution_strategy, [UNTRACKED],
19931997
"how to run proc-macro code (default: same-thread)"),
1994-
profile_closures: bool = (false, parse_no_flag, [UNTRACKED],
1998+
profile_closures: bool = (false, parse_no_value, [UNTRACKED],
19951999
"profile size of closures"),
19962000
profile_sample_use: Option<PathBuf> = (None, parse_opt_pathbuf, [TRACKED],
19972001
"use the given `.prof` file for sampled profile-guided optimization (also known as AutoFDO)"),
@@ -2165,8 +2169,14 @@ written to standard error output)"),
21652169
"enable unsound and buggy MIR optimizations (default: no)"),
21662170
/// This name is kind of confusing: Most unstable options enable something themselves, while
21672171
/// this just allows "normal" options to be feature-gated.
2172+
///
2173+
/// The main check for `-Zunstable-options` takes place separately from the
2174+
/// usual parsing of `-Z` options (see [`crate::config::nightly_options`]),
2175+
/// so this boolean value is mostly used for enabling unstable _values_ of
2176+
/// stable options. That separate check doesn't handle boolean values, so
2177+
/// to avoid an inconsistent state we also forbid them here.
21682178
#[rustc_lint_opt_deny_field_access("use `Session::unstable_options` instead of this field")]
2169-
unstable_options: bool = (false, parse_bool, [UNTRACKED],
2179+
unstable_options: bool = (false, parse_no_value, [UNTRACKED],
21702180
"adds unstable command line options to rustc interface (default: no)"),
21712181
use_ctors_section: Option<bool> = (None, parse_opt_bool, [TRACKED],
21722182
"use legacy .ctors section for initializers rather than .init_array"),

Diff for: tests/ui/codemap_tests/huge_multispan_highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ revisions: ascii unicode
22
//@ compile-flags: --color=always
33
//@[ascii] compile-flags: --error-format=human
4-
//@[unicode] compile-flags: -Zunstable-options=yes --error-format=human-unicode
4+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode
55
//@ ignore-windows
66
fn main() {
77
let _ = match true {

Diff for: tests/ui/diagnostic-width/E0271.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ revisions: ascii unicode
22
//@[ascii] compile-flags: --diagnostic-width=40
3-
//@[unicode] compile-flags: -Zunstable-options=yes --error-format=human-unicode --diagnostic-width=40
3+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode --diagnostic-width=40
44
//@ normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
55
trait Future {
66
type Error;

Diff for: tests/ui/diagnostic-width/flag-human.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ revisions: ascii unicode
22
//@[ascii] compile-flags: --diagnostic-width=20
3-
//@[unicode] compile-flags: -Zunstable-options=yes --error-format=human-unicode --diagnostic-width=20
3+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode --diagnostic-width=20
44

55
// This test checks that `-Z output-width` effects the human error output by restricting it to an
66
// arbitrarily low value so that the effect is visible.

Diff for: tests/ui/diagnostic-width/long-E0308.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ revisions: ascii unicode
22
//@[ascii] compile-flags: --diagnostic-width=60 -Zwrite-long-types-to-disk=yes
3-
//@[unicode] compile-flags: -Zunstable-options=yes --json=diagnostic-unicode --diagnostic-width=60 -Zwrite-long-types-to-disk=yes
3+
//@[unicode] compile-flags: -Zunstable-options --json=diagnostic-unicode --diagnostic-width=60 -Zwrite-long-types-to-disk=yes
44
//@ normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
55

66
mod a {

Diff for: tests/ui/diagnostic-width/non-1-width-unicode-multiline-label.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ revisions: ascii unicode
2-
//@[unicode] compile-flags: -Zunstable-options=yes --error-format=human-unicode
2+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode
33
// ignore-tidy-linelength
44

55
fn main() {

Diff for: tests/ui/diagnostic-width/non-whitespace-trimming-2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//@ revisions: ascii unicode
2-
//@[unicode] compile-flags: -Zunstable-options=yes --error-format=human-unicode
2+
//@[unicode] compile-flags: -Zunstable-options --error-format=human-unicode
33
// ignore-tidy-linelength
44

55
fn main() {

Diff for: tests/ui/error-emitter/unicode-output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ compile-flags: -Zunstable-options=yes --error-format=human-unicode --color=always
1+
//@ compile-flags: -Zunstable-options --error-format=human-unicode --color=always
22
//@ edition:2018
33
//@ only-linux
44

0 commit comments

Comments
 (0)