Skip to content

Commit 44808ae

Browse files
authored
Rollup merge of #135126 - klensy:deprecated-and-do-nothing, r=jieyouxu
mark deprecated option as deprecated in rustc_session to remove copypasta and small refactor This marks deprecated options as deprecated via flag in options table in rustc_session, which removes copypasted deprecation text from rustc_driver_impl. This also adds warning for deprecated `-C ar` option, which didn't emitted any warnings before. Makes `inline_threshold` `[UNTRACKED]`, as it do nothing. Adds few tests. See individual commits.
2 parents 1b370d3 + 37f2631 commit 44808ae

12 files changed

+78
-34
lines changed

compiler/rustc_driver_impl/src/lib.rs

+10-20
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ use rustc_metadata::locator;
5252
use rustc_middle::ty::TyCtxt;
5353
use rustc_parse::{new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal};
5454
use rustc_session::config::{
55-
CG_OPTIONS, ErrorOutputType, Input, OutFileName, OutputType, UnstableOptions, Z_OPTIONS,
56-
nightly_options,
55+
CG_OPTIONS, ErrorOutputType, Input, OptionDesc, OutFileName, OutputType, UnstableOptions,
56+
Z_OPTIONS, nightly_options,
5757
};
5858
use rustc_session::getopts::{self, Matches};
5959
use rustc_session::lint::{Lint, LintId};
@@ -1124,14 +1124,6 @@ pub fn describe_flag_categories(early_dcx: &EarlyDiagCtxt, matches: &Matches) ->
11241124
return true;
11251125
}
11261126

1127-
if cg_flags.iter().any(|x| *x == "no-stack-check") {
1128-
early_dcx.early_warn("the `-Cno-stack-check` flag is deprecated and does nothing");
1129-
}
1130-
1131-
if cg_flags.iter().any(|x| x.starts_with("inline-threshold")) {
1132-
early_dcx.early_warn("the `-Cinline-threshold` flag is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)");
1133-
}
1134-
11351127
if cg_flags.iter().any(|x| *x == "passes=list") {
11361128
let backend_name = debug_flags.iter().find_map(|x| x.strip_prefix("codegen-backend="));
11371129

@@ -1156,18 +1148,16 @@ fn describe_codegen_flags() {
11561148
print_flag_list("-C", config::CG_OPTIONS);
11571149
}
11581150

1159-
fn print_flag_list<T>(
1160-
cmdline_opt: &str,
1161-
flag_list: &[(&'static str, T, &'static str, &'static str)],
1162-
) {
1163-
let max_len = flag_list.iter().map(|&(name, _, _, _)| name.chars().count()).max().unwrap_or(0);
1151+
fn print_flag_list<T>(cmdline_opt: &str, flag_list: &[OptionDesc<T>]) {
1152+
let max_len =
1153+
flag_list.iter().map(|opt_desc| opt_desc.name().chars().count()).max().unwrap_or(0);
11641154

1165-
for &(name, _, _, desc) in flag_list {
1155+
for opt_desc in flag_list {
11661156
safe_println!(
11671157
" {} {:>width$}=val -- {}",
11681158
cmdline_opt,
1169-
name.replace('_', "-"),
1170-
desc,
1159+
opt_desc.name().replace('_', "-"),
1160+
opt_desc.desc(),
11711161
width = max_len
11721162
);
11731163
}
@@ -1221,8 +1211,8 @@ pub fn handle_options(early_dcx: &EarlyDiagCtxt, args: &[String]) -> Option<geto
12211211
let msg: Option<String> = match e {
12221212
getopts::Fail::UnrecognizedOption(ref opt) => CG_OPTIONS
12231213
.iter()
1224-
.map(|&(name, ..)| ('C', name))
1225-
.chain(Z_OPTIONS.iter().map(|&(name, ..)| ('Z', name)))
1214+
.map(|opt_desc| ('C', opt_desc.name()))
1215+
.chain(Z_OPTIONS.iter().map(|opt_desc| ('Z', opt_desc.name())))
12261216
.find(|&(_, name)| *opt == name.replace('_', "-"))
12271217
.map(|(flag, _)| format!("{e}. Did you mean `-{flag} {opt}`?")),
12281218
getopts::Fail::ArgumentMissing(ref opt) => {

compiler/rustc_interface/src/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ fn test_codegen_options_tracking_hash() {
582582
untracked!(dlltool, Some(PathBuf::from("custom_dlltool.exe")));
583583
untracked!(extra_filename, String::from("extra-filename"));
584584
untracked!(incremental, Some(String::from("abc")));
585+
untracked!(inline_threshold, Some(0xf007ba11));
585586
// `link_arg` is omitted because it just forwards to `link_args`.
586587
untracked!(link_args, vec![String::from("abc"), String::from("def")]);
587588
untracked!(link_self_contained, LinkSelfContained::on());
@@ -613,7 +614,6 @@ fn test_codegen_options_tracking_hash() {
613614
tracked!(embed_bitcode, false);
614615
tracked!(force_frame_pointers, FramePointer::Always);
615616
tracked!(force_unwind_tables, Some(true));
616-
tracked!(inline_threshold, Some(0xf007ba11));
617617
tracked!(instrument_coverage, InstrumentCoverage::Yes);
618618
tracked!(link_dead_code, Some(true));
619619
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);

compiler/rustc_session/src/options.rs

+39-9
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ macro_rules! options {
239239
$init:expr,
240240
$parse:ident,
241241
[$dep_tracking_marker:ident],
242-
$desc:expr)
242+
$desc:expr
243+
$(, deprecated_do_nothing: $dnn:literal )?)
243244
),* ,) =>
244245
(
245246
#[derive(Clone)]
@@ -280,7 +281,8 @@ macro_rules! options {
280281
}
281282

282283
pub const $stat: OptionDescrs<$struct_name> =
283-
&[ $( (stringify!($opt), $optmod::$opt, desc::$parse, $desc) ),* ];
284+
&[ $( OptionDesc{ name: stringify!($opt), setter: $optmod::$opt,
285+
type_desc: desc::$parse, desc: $desc, is_deprecated_and_do_nothing: false $( || $dnn )? } ),* ];
284286

285287
mod $optmod {
286288
$(
@@ -315,7 +317,27 @@ macro_rules! redirect_field {
315317
}
316318

317319
type OptionSetter<O> = fn(&mut O, v: Option<&str>) -> bool;
318-
type OptionDescrs<O> = &'static [(&'static str, OptionSetter<O>, &'static str, &'static str)];
320+
type OptionDescrs<O> = &'static [OptionDesc<O>];
321+
322+
pub struct OptionDesc<O> {
323+
name: &'static str,
324+
setter: OptionSetter<O>,
325+
// description for return value/type from mod desc
326+
type_desc: &'static str,
327+
// description for option from options table
328+
desc: &'static str,
329+
is_deprecated_and_do_nothing: bool,
330+
}
331+
332+
impl<O> OptionDesc<O> {
333+
pub fn name(&self) -> &'static str {
334+
self.name
335+
}
336+
337+
pub fn desc(&self) -> &'static str {
338+
self.desc
339+
}
340+
}
319341

320342
#[allow(rustc::untranslatable_diagnostic)] // FIXME: make this translatable
321343
fn build_options<O: Default>(
@@ -333,8 +355,13 @@ fn build_options<O: Default>(
333355
};
334356

335357
let option_to_lookup = key.replace('-', "_");
336-
match descrs.iter().find(|(name, ..)| *name == option_to_lookup) {
337-
Some((_, setter, type_desc, _)) => {
358+
match descrs.iter().find(|opt_desc| opt_desc.name == option_to_lookup) {
359+
Some(OptionDesc { name: _, setter, type_desc, desc, is_deprecated_and_do_nothing }) => {
360+
if *is_deprecated_and_do_nothing {
361+
// deprecation works for prefixed options only
362+
assert!(!prefix.is_empty());
363+
early_dcx.early_warn(format!("`-{prefix} {key}`: {desc}"));
364+
}
338365
if !setter(&mut op, value) {
339366
match value {
340367
None => early_dcx.early_fatal(
@@ -1546,7 +1573,8 @@ options! {
15461573
// tidy-alphabetical-start
15471574
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
15481575
ar: String = (String::new(), parse_string, [UNTRACKED],
1549-
"this option is deprecated and does nothing"),
1576+
"this option is deprecated and does nothing",
1577+
deprecated_do_nothing: true),
15501578
#[rustc_lint_opt_deny_field_access("use `Session::code_model` instead of this field")]
15511579
code_model: Option<CodeModel> = (None, parse_code_model, [TRACKED],
15521580
"choose the code model to use (`rustc --print code-models` for details)"),
@@ -1578,9 +1606,10 @@ options! {
15781606
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
15791607
"enable incremental compilation"),
15801608
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
1581-
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
1609+
inline_threshold: Option<u32> = (None, parse_opt_number, [UNTRACKED],
15821610
"this option is deprecated and does nothing \
1583-
(consider using `-Cllvm-args=--inline-threshold=...`)"),
1611+
(consider using `-Cllvm-args=--inline-threshold=...`)",
1612+
deprecated_do_nothing: true),
15841613
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
15851614
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
15861615
"instrument the generated code to support LLVM source-based code coverage reports \
@@ -1616,7 +1645,8 @@ options! {
16161645
"disable the use of the redzone"),
16171646
#[rustc_lint_opt_deny_field_access("documented to do nothing")]
16181647
no_stack_check: bool = (false, parse_no_value, [UNTRACKED],
1619-
"this option is deprecated and does nothing"),
1648+
"this option is deprecated and does nothing",
1649+
deprecated_do_nothing: true),
16201650
no_vectorize_loops: bool = (false, parse_no_value, [TRACKED],
16211651
"disable loop vectorization optimization passes"),
16221652
no_vectorize_slp: bool = (false, parse_no_value, [TRACKED],

tests/ui/deprecation/deprecated_ar.rs

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ check-pass
2+
//@ compile-flags: -Car=foo
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
warning: `-C ar`: this option is deprecated and does nothing
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
2+
3+
error: incorrect value `asd` for codegen option `inline-threshold` - a number was expected
4+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
warning: `-C inline-threshold`: this option is deprecated and does nothing (consider using `-Cllvm-args=--inline-threshold=...`)
2+
3+
error: codegen option `inline-threshold` requires a number (C inline-threshold=<value>)
4+
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
//@ check-pass
2-
//@ compile-flags: -Cinline-threshold=666
1+
//@ revisions: good_val bad_val no_val
2+
//
3+
//@[good_val] compile-flags: -Cinline-threshold=666
4+
//@[good_val] check-pass
5+
//@[bad_val] compile-flags: -Cinline-threshold=asd
6+
//@[no_val] compile-flags: -Cinline-threshold
37

48
fn main() {}

tests/ui/deprecation/deprecated_inline_threshold.stderr

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//@ check-pass
2+
//@ compile-flags: -Cno-stack-check
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
warning: `-C no-stack-check`: this option is deprecated and does nothing
2+

0 commit comments

Comments
 (0)