Skip to content

Commit 3b206b7

Browse files
committed
Force warn on lint groups as well
1 parent 4675690 commit 3b206b7

19 files changed

+113
-25
lines changed

compiler/rustc_lint/src/context.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,14 @@ impl LintStore {
334334
}
335335
}
336336

337-
/// Checks the validity of lint names derived from the command line
338-
pub fn check_lint_name_cmdline(&self, sess: &Session, lint_name: &str, level: Level) {
337+
/// Checks the validity of lint names derived from the command line. Returns
338+
/// true if the lint is valid, false otherwise.
339+
pub fn check_lint_name_cmdline(
340+
&self,
341+
sess: &Session,
342+
lint_name: &str,
343+
level: Option<Level>,
344+
) -> bool {
339345
let db = match self.check_lint_name(lint_name, None) {
340346
CheckLintNameResult::Ok(_) => None,
341347
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
@@ -361,18 +367,23 @@ impl LintStore {
361367
};
362368

363369
if let Some(mut db) = db {
364-
let msg = format!(
365-
"requested on the command line with `{} {}`",
366-
match level {
367-
Level::Allow => "-A",
368-
Level::Warn => "-W",
369-
Level::Deny => "-D",
370-
Level::Forbid => "-F",
371-
},
372-
lint_name
373-
);
374-
db.note(&msg);
370+
if let Some(level) = level {
371+
let msg = format!(
372+
"requested on the command line with `{} {}`",
373+
match level {
374+
Level::Allow => "-A",
375+
Level::Warn => "-W",
376+
Level::Deny => "-D",
377+
Level::Forbid => "-F",
378+
},
379+
lint_name
380+
);
381+
db.note(&msg);
382+
}
375383
db.emit();
384+
false
385+
} else {
386+
true
376387
}
377388
}
378389

compiler/rustc_lint/src/levels.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'s> LintLevelsBuilder<'s> {
8888
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
8989

9090
for &(ref lint_name, level) in &sess.opts.lint_opts {
91-
store.check_lint_name_cmdline(sess, &lint_name, level);
91+
store.check_lint_name_cmdline(sess, &lint_name, Some(level));
9292
let orig_level = level;
9393

9494
// If the cap is less than this specified level, e.g., if we've got
@@ -110,8 +110,13 @@ impl<'s> LintLevelsBuilder<'s> {
110110
}
111111

112112
for lint_name in &sess.opts.force_warns {
113-
store.check_lint_name_cmdline(sess, &lint_name, Level::Allow); // FIXME level is wrong
114-
self.sets.force_warns.insert(lint_name.to_uppercase());
113+
let valid = store.check_lint_name_cmdline(sess, lint_name, None);
114+
if valid {
115+
let lints = store
116+
.find_lints(lint_name)
117+
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
118+
self.sets.force_warns.extend(&lints);
119+
}
115120
}
116121

117122
self.sets.list.push(LintSet::CommandLine { specs });

compiler/rustc_middle/src/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub type LevelAndSource = (Level, LintLevelSource);
6060
pub struct LintLevelSets {
6161
pub list: Vec<LintSet>,
6262
pub lint_cap: Level,
63-
pub force_warns: FxHashSet<String>,
63+
pub force_warns: FxHashSet<LintId>,
6464
}
6565

6666
#[derive(Debug)]
@@ -94,7 +94,7 @@ impl LintLevelSets {
9494
sess: &Session,
9595
) -> LevelAndSource {
9696
// Check whether we should always warn
97-
if self.force_warns.contains(lint.name) {
97+
if self.force_warns.contains(&LintId::of(lint)) {
9898
return (Level::Warn, LintLevelSource::ForceWarn(Symbol::intern(lint.name)));
9999
}
100100

compiler/rustc_session/src/config.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
11641164
pub fn get_cmd_lint_options(
11651165
matches: &getopts::Matches,
11661166
error_format: ErrorOutputType,
1167+
debugging_opts: &DebuggingOptions,
11671168
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>, Vec<String>) {
11681169
let mut lint_opts_with_position = vec![];
11691170
let mut describe_lints = false;
@@ -1198,6 +1199,14 @@ pub fn get_cmd_lint_options(
11981199
.unwrap_or_else(|| early_error(error_format, &format!("unknown lint level: `{}`", cap)))
11991200
});
12001201

1202+
if !debugging_opts.unstable_options && matches.opt_present("force-warns") {
1203+
early_error(
1204+
error_format,
1205+
"the `-Z unstable-options` flag must also be passed to enable \
1206+
the flag `--force-warns=lints`",
1207+
);
1208+
}
1209+
12011210
let force_warns = matches.opt_strs("force-warns");
12021211

12031212
(lint_opts, describe_lints, lint_cap, force_warns)
@@ -1937,10 +1946,10 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
19371946
let crate_types = parse_crate_types_from_list(unparsed_crate_types)
19381947
.unwrap_or_else(|e| early_error(error_format, &e[..]));
19391948

1949+
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
19401950
let (lint_opts, describe_lints, lint_cap, force_warns) =
1941-
get_cmd_lint_options(matches, error_format);
1951+
get_cmd_lint_options(matches, error_format, &debugging_opts);
19421952

1943-
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
19441953
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
19451954

19461955
if !debugging_opts.unstable_options && json_unused_externs {

src/librustdoc/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,8 @@ impl Options {
635635
let generate_redirect_map = matches.opt_present("generate-redirect-map");
636636
let show_type_layout = matches.opt_present("show-type-layout");
637637

638-
let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
638+
let (lint_opts, describe_lints, lint_cap, _) =
639+
get_cmd_lint_options(matches, error_format, &debugging_opts);
639640

640641
Ok(Options {
641642
input,

src/librustdoc/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ fn opts() -> Vec<RustcOptGroup> {
510510
"LEVEL",
511511
)
512512
}),
513+
unstable("force-warns", |o| {
514+
o.optopt(
515+
"",
516+
"force-warns",
517+
"Lints that will warn even if allowed somewhere else",
518+
"LINTS",
519+
)
520+
}),
513521
unstable("index-page", |o| {
514522
o.optopt("", "index-page", "Markdown file to be used as index page", "PATH")
515523
}),

src/test/ui/lint/force-warn/force-allow-by-default.stderr renamed to src/test/ui/lint/force-warn/force-allowed-by-default-lint.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: hidden lifetime parameters in types are deprecated
2-
--> $DIR/force-allow-by-default.rs:8:12
2+
--> $DIR/force-allowed-by-default-lint.rs:8:12
33
|
44
LL | fn foo(x: &Foo) {}
55
| ^^^- help: indicate the anonymous lifetime: `<'_>`

0 commit comments

Comments
 (0)