Make ForceWarn a lint level.
This commit is contained in:
parent
6830052c7b
commit
e42271db0d
13 changed files with 48 additions and 76 deletions
|
@ -334,14 +334,8 @@ impl LintStore {
|
|||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
/// 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) {
|
||||
let db = match self.check_lint_name(lint_name, None) {
|
||||
CheckLintNameResult::Ok(_) => None,
|
||||
CheckLintNameResult::Warning(ref msg, _) => Some(sess.struct_warn(msg)),
|
||||
|
@ -367,23 +361,19 @@ impl LintStore {
|
|||
};
|
||||
|
||||
if let Some(mut db) = db {
|
||||
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);
|
||||
}
|
||||
let msg = format!(
|
||||
"requested on the command line with `{} {}`",
|
||||
match level {
|
||||
Level::Allow => "-A",
|
||||
Level::Warn => "-W",
|
||||
Level::ForceWarn => "--force-warns",
|
||||
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, Some(level));
|
||||
store.check_lint_name_cmdline(sess, &lint_name, level);
|
||||
let orig_level = level;
|
||||
|
||||
// If the cap is less than this specified level, e.g., if we've got
|
||||
|
@ -110,12 +110,13 @@ 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);
|
||||
store.check_lint_name_cmdline(sess, lint_name, Level::ForceWarn);
|
||||
let lints = store
|
||||
.find_lints(lint_name)
|
||||
.unwrap_or_else(|_| bug!("A valid lint failed to produce a lint ids"));
|
||||
for id in lints {
|
||||
let src = LintLevelSource::CommandLine(Symbol::intern(lint_name), Level::ForceWarn);
|
||||
specs.insert(id, (Level::ForceWarn, src));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +132,8 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
id: LintId,
|
||||
(level, src): LevelAndSource,
|
||||
) {
|
||||
let (old_level, old_src) =
|
||||
self.sets.get_lint_level(id.lint, self.cur, Some(&specs), &self.sess);
|
||||
// Setting to a non-forbid level is an error if the lint previously had
|
||||
// a forbid level. Note that this is not necessarily true even with a
|
||||
// `#[forbid(..)]` attribute present, as that is overriden by `--cap-lints`.
|
||||
|
@ -138,9 +141,7 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
// This means that this only errors if we're truly lowering the lint
|
||||
// level from forbid.
|
||||
if level != Level::Forbid {
|
||||
if let (Level::Forbid, old_src) =
|
||||
self.sets.get_lint_level(id.lint, self.cur, Some(&specs), &self.sess)
|
||||
{
|
||||
if let Level::Forbid = old_level {
|
||||
// Backwards compatibility check:
|
||||
//
|
||||
// We used to not consider `forbid(lint_group)`
|
||||
|
@ -152,9 +153,6 @@ 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={:?}",
|
||||
|
@ -179,7 +177,6 @@ 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();
|
||||
};
|
||||
|
@ -216,7 +213,11 @@ impl<'s> LintLevelsBuilder<'s> {
|
|||
}
|
||||
}
|
||||
}
|
||||
specs.insert(id, (level, src));
|
||||
if let Level::ForceWarn = old_level {
|
||||
specs.insert(id, (old_level, old_src));
|
||||
} else {
|
||||
specs.insert(id, (level, src));
|
||||
}
|
||||
}
|
||||
|
||||
/// Pushes a list of AST lint attributes onto this context.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue