about summary refs log tree commit diff
diff options
context:
space:
mode:
authorklensy <klensy@users.noreply.github.com>2025-01-05 15:32:20 +0300
committerklensy <klensy@users.noreply.github.com>2025-01-06 15:38:02 +0300
commit37f26311ebd2895e8052a4caa4c89dedf6fbef9d (patch)
tree367889150aff23241b0d5bb399ab8bb1c26519f9
parent7270e73b622d60e770936ace5271a068fa32785b (diff)
downloadrust-37f26311ebd2895e8052a4caa4c89dedf6fbef9d.tar.gz
rust-37f26311ebd2895e8052a4caa4c89dedf6fbef9d.zip
add deprecated and do nothing flag to options table
inline_threshold mark deprecated

no-stack-check

print deprecation message for -Car too

inline_threshold deprecated and do nothing: make in untracked

make OptionDesc struct from tuple
-rw-r--r--compiler/rustc_driver_impl/src/lib.rs30
-rw-r--r--compiler/rustc_interface/src/tests.rs2
-rw-r--r--compiler/rustc_session/src/options.rs48
-rw-r--r--tests/ui/deprecation/deprecated_ar.rs4
-rw-r--r--tests/ui/deprecation/deprecated_ar.stderr2
-rw-r--r--tests/ui/deprecation/deprecated_inline_threshold.bad_val.stderr4
-rw-r--r--tests/ui/deprecation/deprecated_inline_threshold.good_val.stderr2
-rw-r--r--tests/ui/deprecation/deprecated_inline_threshold.no_val.stderr4
-rw-r--r--tests/ui/deprecation/deprecated_inline_threshold.rs8
-rw-r--r--tests/ui/deprecation/deprecated_inline_threshold.stderr2
-rw-r--r--tests/ui/deprecation/deprecated_no_stack_check_opt.rs4
-rw-r--r--tests/ui/deprecation/deprecated_no_stack_check_opt.stderr2
12 files changed, 78 insertions, 34 deletions
diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs
index 90f382e7226..0413e5e8634 100644
--- a/compiler/rustc_driver_impl/src/lib.rs
+++ b/compiler/rustc_driver_impl/src/lib.rs
@@ -52,8 +52,8 @@ use rustc_metadata::locator;
 use rustc_middle::ty::TyCtxt;
 use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
 use rustc_session::config::{
-    CG_OPTIONS, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, Z_OPTIONS,
-    nightly_options,
+    CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
+    Z_OPTIONS, nightly_options,
 };
 use rustc_session::getopts::{self, Matches};
 use rustc_session::lint::{Lint, LintId};
@@ -1124,14 +1124,6 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
         return true;
     }
 
-    if cg_flags.iter().any(|x| *x == "no-stack-check") {
-        early_dcx.early_warn("the `-Cno-stack-check` flag is deprecated and does nothing");
-    }
-
-    if cg_flags.iter().any(|x| x.starts_with("inline-threshold")) {
-        early_dcx.early_warn("the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)");
-    }
-
     if cg_flags.iter().any(|x| *x == "passes=list") {
         let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
 
@@ -1156,18 +1148,16 @@ fn describe_codegen_flags() {
     print_flag_list("-C", config::CG_OPTIONS);
 }
 
-fn print_flag_list<T>(
-    cmdline_opt: &str,
-    flag_list: &[(&'static str, T, &'static str, &'static str)],
-) {
-    let max_len = flag_list.iter().map(|&(name, _, _, _)| name.chars().count()).max().unwrap_or(0);
+fn print_flag_list<T>(cmdline_opt: &str, flag_list: &[OptionDesc<T>]) {
+    let max_len =
+        flag_list.iter().map(|opt_desc| opt_desc.name().chars().count()).max().unwrap_or(0);
 
-    for &(name, _, _, desc) in flag_list {
+    for opt_desc in flag_list {
         safe_println!(
             "    {} {:>width$}=val -- {}",
             cmdline_opt,
-            name.replace('_', "-"),
-            desc,
+            opt_desc.name().replace('_', "-"),
+            opt_desc.desc(),
             width = max_len
         );
     }
@@ -1221,8 +1211,8 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
         let msg: Option<String> = match e {
             getopts::Fail::UnrecognizedOption(ref opt) => CG_OPTIONS
                 .iter()
-                .map(|&(name, ..)| ('C', name))
-                .chain(Z_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
+                .map(|opt_desc| ('C', opt_desc.name()))
+                .chain(Z_OPTIONS.iter().map(|opt_desc| ('Z', opt_desc.name())))
                 .find(|&(_, name)| *opt == name.replace('_', "-"))
                 .map(|(flag, _)| format!("{e}. Did you mean `-{flag} {opt}`?")),
             getopts::Fail::ArgumentMissing(ref opt) => {
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index 9ad69039914..bb5f1c295c7 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -582,6 +582,7 @@ fn test_codegen_options_tracking_hash() {
     untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
     untracked!(extra_filename, String::from("extra-filename"));
     untracked!(incremental, Some(String::from("abc")));
+    untracked!(inline_threshold, Some(0xf007ba11));
     // `link_arg` is omitted because it just forwards to `link_args`.
     untracked!(link_args, vec![String::from("abc"), String::from("def")]);
     untracked!(link_self_contained, LinkSelfContained::on());
@@ -613,7 +614,6 @@ fn test_codegen_options_tracking_hash() {
     tracked!(embed_bitcode, false);
     tracked!(force_frame_pointers, FramePointer::Always);
     tracked!(force_unwind_tables, Some(true));
-    tracked!(inline_threshold, Some(0xf007ba11));
     tracked!(instrument_coverage, InstrumentCoverage::Yes);
     tracked!(link_dead_code, Some(true));
     tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 3772a4a08af..30047339810 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -239,7 +239,8 @@ macro_rules! options {
         $init:expr,
         $parse:ident,
         [$dep_tracking_marker:ident],
-        $desc:expr)
+        $desc:expr
+        $(, deprecated_do_nothing: $dnn:literal )?)
      ),* ,) =>
 (
     #[derive(Clone)]
@@ -280,7 +281,8 @@ macro_rules! options {
     }
 
     pub const $stat: OptionDescrs<$struct_name> =
-        &[ $( (stringify!($opt), $optmod::$opt, desc::$parse, $desc) ),* ];
+        &[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
+            type_desc: desc::$parse, desc: $desc, is_deprecated_and_do_nothing: false $( || $dnn )? } ),* ];
 
     mod $optmod {
     $(
@@ -315,7 +317,27 @@ macro_rules! redirect_field {
 }
 
 type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
-type OptionDescrs<O> = &'static [(&'static str, OptionSetter<O>, &'static str, &'static str)];
+type OptionDescrs<O> = &'static [OptionDesc<O>];
+
+pub struct OptionDesc<O> {
+    name: &'static str,
+    setter: OptionSetter<O>,
+    // description for return value/type from mod desc
+    type_desc: &'static str,
+    // description for option from options table
+    desc: &'static str,
+    is_deprecated_and_do_nothing: bool,
+}
+
+impl<O> OptionDesc<O> {
+    pub fn name(&self) -> &'static str {
+        self.name
+    }
+
+    pub fn desc(&self) -> &'static str {
+        self.desc
+    }
+}
 
 #[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
 fn build_options<O: Default>(
@@ -333,8 +355,13 @@ fn build_options<O: Default>(
         };
 
         let option_to_lookup = key.replace('-', "_");
-        match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
-            Some((_, setter, type_desc, _)) => {
+        match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) {
+            Some(OptionDesc { name: _, setter, type_desc, desc, is_deprecated_and_do_nothing }) => {
+                if *is_deprecated_and_do_nothing {
+                    // deprecation works for prefixed options only
+                    assert!(!prefix.is_empty());
+                    early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"));
+                }
                 if !setter(&mut op, value) {
                     match value {
                         None => early_dcx.early_fatal(
@@ -1546,7 +1573,8 @@ options! {
     // tidy-alphabetical-start
     #[rustc_lint_opt_deny_field_access("documented to do nothing")]
     ar: String = (String::new(), parse_string, [UNTRACKED],
-        "this option is deprecated and does nothing"),
+        "this option is deprecated and does nothing",
+        deprecated_do_nothing: true),
     #[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
     code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
         "choose the code model to use (`rustc --print code-models` for details)"),
@@ -1578,9 +1606,10 @@ options! {
     incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
         "enable incremental compilation"),
     #[rustc_lint_opt_deny_field_access("documented to do nothing")]
-    inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
+    inline_threshold: Option<u32> = (None, parse_opt_number, [UNTRACKED],
         "this option is deprecated and does nothing \
-        (consider using `-Cllvm-args=--inline-threshold=...`)"),
+        (consider using `-Cllvm-args=--inline-threshold=...`)",
+        deprecated_do_nothing: true),
     #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
     instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
         "instrument the generated code to support LLVM source-based code coverage reports \
@@ -1616,7 +1645,8 @@ options! {
         "disable the use of the redzone"),
     #[rustc_lint_opt_deny_field_access("documented to do nothing")]
     no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
-        "this option is deprecated and does nothing"),
+        "this option is deprecated and does nothing",
+        deprecated_do_nothing: true),
     no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
         "disable loop vectorization optimization passes"),
     no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],
diff --git a/tests/ui/deprecation/deprecated_ar.rs b/tests/ui/deprecation/deprecated_ar.rs
new file mode 100644
index 00000000000..404d062e6a4
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_ar.rs
@@ -0,0 +1,4 @@
+//@ check-pass
+//@ compile-flags: -Car=foo
+
+fn main() {}
diff --git a/tests/ui/deprecation/deprecated_ar.stderr b/tests/ui/deprecation/deprecated_ar.stderr
new file mode 100644
index 00000000000..de776c67499
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_ar.stderr
@@ -0,0 +1,2 @@
+warning: `-C ar`: this option is deprecated and does nothing
+
diff --git a/tests/ui/deprecation/deprecated_inline_threshold.bad_val.stderr b/tests/ui/deprecation/deprecated_inline_threshold.bad_val.stderr
new file mode 100644
index 00000000000..2e7a99010ae
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_inline_threshold.bad_val.stderr
@@ -0,0 +1,4 @@
+warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
+
+error: incorrect value `asd` for codegen option `inline-threshold` - a number was expected
+
diff --git a/tests/ui/deprecation/deprecated_inline_threshold.good_val.stderr b/tests/ui/deprecation/deprecated_inline_threshold.good_val.stderr
new file mode 100644
index 00000000000..2d6f3652d25
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_inline_threshold.good_val.stderr
@@ -0,0 +1,2 @@
+warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
+
diff --git a/tests/ui/deprecation/deprecated_inline_threshold.no_val.stderr b/tests/ui/deprecation/deprecated_inline_threshold.no_val.stderr
new file mode 100644
index 00000000000..25104e637e0
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_inline_threshold.no_val.stderr
@@ -0,0 +1,4 @@
+warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
+
+error: codegen option `inline-threshold` requires a number (C inline-threshold=<value>)
+
diff --git a/tests/ui/deprecation/deprecated_inline_threshold.rs b/tests/ui/deprecation/deprecated_inline_threshold.rs
index 56e033b8cf5..b54fa36397a 100644
--- a/tests/ui/deprecation/deprecated_inline_threshold.rs
+++ b/tests/ui/deprecation/deprecated_inline_threshold.rs
@@ -1,4 +1,8 @@
-//@ check-pass
-//@ compile-flags: -Cinline-threshold=666
+//@ revisions: good_val bad_val no_val
+//
+//@[good_val] compile-flags: -Cinline-threshold=666
+//@[good_val] check-pass
+//@[bad_val] compile-flags: -Cinline-threshold=asd
+//@[no_val] compile-flags: -Cinline-threshold
 
 fn main() {}
diff --git a/tests/ui/deprecation/deprecated_inline_threshold.stderr b/tests/ui/deprecation/deprecated_inline_threshold.stderr
deleted file mode 100644
index c4f8ff092b2..00000000000
--- a/tests/ui/deprecation/deprecated_inline_threshold.stderr
+++ /dev/null
@@ -1,2 +0,0 @@
-warning: the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
-
diff --git a/tests/ui/deprecation/deprecated_no_stack_check_opt.rs b/tests/ui/deprecation/deprecated_no_stack_check_opt.rs
new file mode 100644
index 00000000000..62584ec23e3
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_no_stack_check_opt.rs
@@ -0,0 +1,4 @@
+//@ check-pass
+//@ compile-flags: -Cno-stack-check
+
+fn main() {}
diff --git a/tests/ui/deprecation/deprecated_no_stack_check_opt.stderr b/tests/ui/deprecation/deprecated_no_stack_check_opt.stderr
new file mode 100644
index 00000000000..17efba787f0
--- /dev/null
+++ b/tests/ui/deprecation/deprecated_no_stack_check_opt.stderr
@@ -0,0 +1,2 @@
+warning: `-C no-stack-check`: this option is deprecated and does nothing
+