Skip to content

Commit 03f2cf2

Browse files
Make --force-warns a normal lint level option
1 parent ac8c3bf commit 03f2cf2

File tree

4 files changed

+20
-39
lines changed

4 files changed

+20
-39
lines changed

compiler/rustc_lint/src/levels.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,18 @@ impl<'s> LintLevelsBuilder<'s> {
104104
Err(_) => continue, // errors handled in check_lint_name_cmdline above
105105
};
106106
for id in ids {
107+
// ForceWarn and Forbid cannot be overriden
108+
match specs.get(&id) {
109+
Some((Level::ForceWarn | Level::Forbid, _)) => continue,
110+
_ => (),
111+
}
112+
107113
self.check_gated_lint(id, DUMMY_SP);
108114
let src = LintLevelSource::CommandLine(lint_flag_val, orig_level);
109115
specs.insert(id, (level, src));
110116
}
111117
}
112118

113-
for lint_name in &sess.opts.force_warns {
114-
store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn, self.crate_attrs);
115-
let lints = store
116-
.find_lints(lint_name)
117-
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
118-
for id in lints {
119-
let src = LintLevelSource::CommandLine(Symbol::intern(lint_name), Level::ForceWarn);
120-
specs.insert(id, (Level::ForceWarn, src));
121-
}
122-
}
123-
124119
self.cur = self.sets.list.push(LintSet { specs, parent: COMMAND_LINE });
125120
}
126121

compiler/rustc_session/src/config.rs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,6 @@ impl Default for Options {
677677
optimize: OptLevel::No,
678678
debuginfo: DebugInfo::None,
679679
lint_opts: Vec::new(),
680-
force_warns: Vec::new(),
681680
lint_cap: None,
682681
describe_lints: false,
683682
output_types: OutputTypes(BTreeMap::new()),
@@ -1170,20 +1169,20 @@ pub fn get_cmd_lint_options(
11701169
matches: &getopts::Matches,
11711170
error_format: ErrorOutputType,
11721171
debugging_opts: &DebuggingOptions,
1173-
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>, Vec<String>) {
1172+
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
11741173
let mut lint_opts_with_position = vec![];
11751174
let mut describe_lints = false;
11761175

1177-
for level in [lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
1178-
for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
1179-
let arg_pos = if let lint::Forbid = level {
1180-
// HACK: forbid is always specified last, so it can't be overridden.
1181-
// FIXME: remove this once <https://github.com/rust-lang/rust/issues/70819> is
1182-
// fixed and `forbid` works as expected.
1183-
usize::MAX
1184-
} else {
1185-
passed_arg_pos
1186-
};
1176+
if !debugging_opts.unstable_options && matches.opt_present("force-warns") {
1177+
early_error(
1178+
error_format,
1179+
"the `-Z unstable-options` flag must also be passed to enable \
1180+
the flag `--force-warns=lints`",
1181+
);
1182+
}
1183+
1184+
for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] {
1185+
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
11871186
if lint_name == "help" {
11881187
describe_lints = true;
11891188
} else {
@@ -1204,18 +1203,7 @@ pub fn get_cmd_lint_options(
12041203
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
12051204
});
12061205

1207-
if !debugging_opts.unstable_options && matches.opt_present("force-warns") {
1208-
early_error(
1209-
error_format,
1210-
"the `-Z unstable-options` flag must also be passed to enable \
1211-
the flag `--force-warns=lints`",
1212-
);
1213-
}
1214-
1215-
let force_warns =
1216-
matches.opt_strs("force-warns").into_iter().map(|name| name.replace('-', "_")).collect();
1217-
1218-
(lint_opts, describe_lints, lint_cap, force_warns)
1206+
(lint_opts, describe_lints, lint_cap)
12191207
}
12201208

12211209
/// Parses the `--color` flag.
@@ -1953,7 +1941,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
19531941
.unwrap_or_else(|e| early_error(error_format, &e[..]));
19541942

19551943
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
1956-
let (lint_opts, describe_lints, lint_cap, force_warns) =
1944+
let (lint_opts, describe_lints, lint_cap) =
19571945
get_cmd_lint_options(matches, error_format, &debugging_opts);
19581946

19591947
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
@@ -2127,7 +2115,6 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
21272115
optimize: opt_level,
21282116
debuginfo,
21292117
lint_opts,
2130-
force_warns,
21312118
lint_cap,
21322119
describe_lints,
21332120
output_types,

compiler/rustc_session/src/options.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ top_level_options!(
135135
debuginfo: DebugInfo [TRACKED],
136136
lint_opts: Vec<(String, lint::Level)> [TRACKED],
137137
lint_cap: Option<lint::Level> [TRACKED],
138-
force_warns: Vec<String> [TRACKED],
139138
describe_lints: bool [UNTRACKED],
140139
output_types: OutputTypes [TRACKED],
141140
search_paths: Vec<SearchPath> [UNTRACKED],

src/librustdoc/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ impl Options {
628628
let generate_redirect_map = matches.opt_present("generate-redirect-map");
629629
let show_type_layout = matches.opt_present("show-type-layout");
630630

631-
let (lint_opts, describe_lints, lint_cap, _) =
631+
let (lint_opts, describe_lints, lint_cap) =
632632
get_cmd_lint_options(matches, error_format, &debugging_opts);
633633

634634
Ok(Options {

0 commit comments

Comments
 (0)