Auto merge of #43841 - alexcrichton:fix-another-regression, r=eddyb
rustc: Fix `unknown_lints` next to an unknown lint The lint refactoring in #43522 didn't account for `#[allow(unknown_lints)]` happening at the same node as an unknown lint itself, so this commit updates the handling to ensure that the local set of lint configuration being built is queried before looking at the chain of lint levels. Closes #43809
This commit is contained in:
commit
85eadf84f3
@ -83,10 +83,13 @@ impl LintLevelSets {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lint_level(&self, lint: &'static Lint, idx: u32)
|
fn get_lint_level(&self,
|
||||||
|
lint: &'static Lint,
|
||||||
|
idx: u32,
|
||||||
|
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>)
|
||||||
-> (Level, LintSource)
|
-> (Level, LintSource)
|
||||||
{
|
{
|
||||||
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx);
|
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
|
||||||
|
|
||||||
// If `level` is none then we actually assume the default level for this
|
// If `level` is none then we actually assume the default level for this
|
||||||
// lint.
|
// lint.
|
||||||
@ -97,7 +100,9 @@ impl LintLevelSets {
|
|||||||
// `allow(warnings)` in scope then we want to respect that instead.
|
// `allow(warnings)` in scope then we want to respect that instead.
|
||||||
if level == Level::Warn {
|
if level == Level::Warn {
|
||||||
let (warnings_level, warnings_src) =
|
let (warnings_level, warnings_src) =
|
||||||
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS), idx);
|
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS),
|
||||||
|
idx,
|
||||||
|
aux);
|
||||||
if let Some(configured_warning_level) = warnings_level {
|
if let Some(configured_warning_level) = warnings_level {
|
||||||
if configured_warning_level != Level::Warn {
|
if configured_warning_level != Level::Warn {
|
||||||
level = configured_warning_level;
|
level = configured_warning_level;
|
||||||
@ -112,9 +117,17 @@ impl LintLevelSets {
|
|||||||
return (level, src)
|
return (level, src)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_lint_id_level(&self, id: LintId, mut idx: u32)
|
fn get_lint_id_level(&self,
|
||||||
|
id: LintId,
|
||||||
|
mut idx: u32,
|
||||||
|
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>)
|
||||||
-> (Option<Level>, LintSource)
|
-> (Option<Level>, LintSource)
|
||||||
{
|
{
|
||||||
|
if let Some(specs) = aux {
|
||||||
|
if let Some(&(level, src)) = specs.get(&id) {
|
||||||
|
return (Some(level), src)
|
||||||
|
}
|
||||||
|
}
|
||||||
loop {
|
loop {
|
||||||
match self.list[idx as usize] {
|
match self.list[idx as usize] {
|
||||||
LintSet::CommandLine { ref specs } => {
|
LintSet::CommandLine { ref specs } => {
|
||||||
@ -212,31 +225,45 @@ impl<'a> LintLevelsBuilder<'a> {
|
|||||||
specs.insert(*id, (level, src));
|
specs.insert(*id, (level, src));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_ if !self.warn_about_weird_lints => {}
|
||||||
|
|
||||||
CheckLintNameResult::Warning(ref msg) => {
|
CheckLintNameResult::Warning(ref msg) => {
|
||||||
if self.warn_about_weird_lints {
|
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
|
||||||
self.struct_lint(builtin::RENAMED_AND_REMOVED_LINTS,
|
let (level, src) = self.sets.get_lint_level(lint,
|
||||||
|
self.cur,
|
||||||
|
Some(&specs));
|
||||||
|
lint::struct_lint_level(self.sess,
|
||||||
|
lint,
|
||||||
|
level,
|
||||||
|
src,
|
||||||
Some(li.span.into()),
|
Some(li.span.into()),
|
||||||
msg)
|
msg)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
CheckLintNameResult::NoLint => {
|
CheckLintNameResult::NoLint => {
|
||||||
if self.warn_about_weird_lints {
|
let lint = builtin::UNKNOWN_LINTS;
|
||||||
self.struct_lint(builtin::UNKNOWN_LINTS,
|
let (level, src) = self.sets.get_lint_level(lint,
|
||||||
|
self.cur,
|
||||||
|
Some(&specs));
|
||||||
|
let msg = format!("unknown lint: `{}`", name);
|
||||||
|
lint::struct_lint_level(self.sess,
|
||||||
|
lint,
|
||||||
|
level,
|
||||||
|
src,
|
||||||
Some(li.span.into()),
|
Some(li.span.into()),
|
||||||
&format!("unknown lint: `{}`", name))
|
&msg)
|
||||||
.emit();
|
.emit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
for (id, &(level, ref src)) in specs.iter() {
|
for (id, &(level, ref src)) in specs.iter() {
|
||||||
if level == Level::Forbid {
|
if level == Level::Forbid {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
let forbid_src = match self.sets.get_lint_id_level(*id, self.cur) {
|
let forbid_src = match self.sets.get_lint_id_level(*id, self.cur, None) {
|
||||||
(Some(Level::Forbid), src) => src,
|
(Some(Level::Forbid), src) => src,
|
||||||
_ => continue,
|
_ => continue,
|
||||||
};
|
};
|
||||||
@ -298,7 +325,7 @@ impl<'a> LintLevelsBuilder<'a> {
|
|||||||
msg: &str)
|
msg: &str)
|
||||||
-> DiagnosticBuilder<'a>
|
-> DiagnosticBuilder<'a>
|
||||||
{
|
{
|
||||||
let (level, src) = self.sets.get_lint_level(lint, self.cur);
|
let (level, src) = self.sets.get_lint_level(lint, self.cur, None);
|
||||||
lint::struct_lint_level(self.sess, lint, level, src, span, msg)
|
lint::struct_lint_level(self.sess, lint, level, src, span, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -337,7 +364,7 @@ impl LintLevelMap {
|
|||||||
-> Option<(Level, LintSource)>
|
-> Option<(Level, LintSource)>
|
||||||
{
|
{
|
||||||
self.id_to_set.get(&id).map(|idx| {
|
self.id_to_set.get(&id).map(|idx| {
|
||||||
self.sets.get_lint_level(lint, *idx)
|
self.sets.get_lint_level(lint, *idx, None)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
16
src/test/run-pass/lint-unknown-lints-at-crate-level.rs
Normal file
16
src/test/run-pass/lint-unknown-lints-at-crate-level.rs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
// compile-flags: -D warnings -D unknown-lints
|
||||||
|
|
||||||
|
#![allow(unknown_lints)]
|
||||||
|
#![allow(random_lint_name)]
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in New Issue
Block a user