Auto merge of #85788 - rylev:force-warns, r=nikomatsakis
Support for force-warns Implements https://github.com/rust-lang/rust/issues/85512. This PR adds a new command line option `force-warns` which will force the provided lints to warn even if they are allowed by some other mechanism such as `#![allow(warnings)]`. Some remaining issues: * https://github.com/rust-lang/rust/issues/85512 mentions that `force-warns` should also be capable of taking lint groups instead of individual lints. This is not implemented. * If a lint has a higher warning level than `warn`, this will cause that lint to warn instead. We probably want to allow the lint to error if it is set to a higher lint and is not allowed somewhere else. * One test is currently ignored because it's not working - when a deny-by-default lint is allowed, it does not currently warn under `force-warns`. I'm not sure why, but I wanted to get this in before the weekend. r? `@nikomatsakis`
This commit is contained in:
commit
595088d602
28 changed files with 321 additions and 23 deletions
|
@ -334,8 +334,14 @@ impl LintStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// Checks the validity of lint names derived from the command line
|
||||
pub fn check_lint_name_cmdline(&self, sess: &Session, lint_name: &str, level: Level) {
|
||||
/// Checks the validity of lint names derived from the command line. Returns
|
||||
/// true if the lint is valid, false otherwise.
|
||||
pub fn check_lint_name_cmdline(
|
||||
&self,
|
||||
sess: &Session,
|
||||
lint_name: &str,
|
||||
level: Option<Level>,
|
||||
) -> bool {
|
||||
let db = match self.check_lint_name(lint_name, None) {
|
||||
CheckLintNameResult::Ok(_) => None,
|
||||
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
|
||||
|
@ -361,18 +367,23 @@ impl LintStore {
|
|||
};
|
||||
|
||||
if let Some(mut db) = db {
|
||||
let msg = format!(
|
||||
"requested on the command line with `{} {}`",
|
||||
match level {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
},
|
||||
lint_name
|
||||
);
|
||||
db.note(&msg);
|
||||
if let Some(level) = level {
|
||||
let msg = format!(
|
||||
"requested on the command line with `{} {}`",
|
||||
match level {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::Deny => "-D",
|
||||
Level::Forbid => "-F",
|
||||
},
|
||||
lint_name
|
||||
);
|
||||
db.note(&msg);
|
||||
}
|
||||
db.emit();
|
||||
false
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -88,7 +88,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
self.sets.lint_cap = sess.opts.lint_cap.unwrap_or(Level::Forbid);
|
||||
|
||||
for &(ref lint_name, level) in &sess.opts.lint_opts {
|
||||
store.check_lint_name_cmdline(sess, &lint_name, level);
|
||||
store.check_lint_name_cmdline(sess, &lint_name, Some(level));
|
||||
let orig_level = level;
|
||||
|
||||
// If the cap is less than this specified level, e.g., if we've got
|
||||
|
@ -109,6 +109,16 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
}
|
||||
}
|
||||
|
||||
for lint_name in &sess.opts.force_warns {
|
||||
let valid = store.check_lint_name_cmdline(sess, lint_name, None);
|
||||
if valid {
|
||||
let lints = store
|
||||
.find_lints(lint_name)
|
||||
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
|
||||
self.sets.force_warns.extend(&lints);
|
||||
}
|
||||
}
|
||||
|
||||
self.sets.list.push(LintSet::CommandLine { specs });
|
||||
}
|
||||
|
||||
|
@ -142,6 +152,9 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
LintLevelSource::Default => false,
|
||||
LintLevelSource::Node(symbol, _, _) => self.store.is_lint_group(symbol),
|
||||
LintLevelSource::CommandLine(symbol, _) => self.store.is_lint_group(symbol),
|
||||
LintLevelSource::ForceWarn(_symbol) => {
|
||||
bug!("forced warn lint returned a forbid lint level")
|
||||
}
|
||||
};
|
||||
debug!(
|
||||
"fcw_warning={:?}, specs.get(&id) = {:?}, old_src={:?}, id_name={:?}",
|
||||
|
@ -166,6 +179,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
LintLevelSource::CommandLine(_, _) => {
|
||||
diag_builder.note("`forbid` lint level was set on command line");
|
||||
}
|
||||
_ => bug!("forced warn lint returned a forbid lint level"),
|
||||
}
|
||||
diag_builder.emit();
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue