Skip to content

Commit 85eadf8

Browse files
committed
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
2 parents 4fc3765 + 8b2bdc5 commit 85eadf8

File tree

2 files changed

+62
-19
lines changed

2 files changed

+62
-19
lines changed

src/librustc/lint/levels.rs

+46-19
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,13 @@ impl LintLevelSets {
8383
});
8484
}
8585

86-
fn get_lint_level(&self, lint: &'static Lint, idx: u32)
86+
fn get_lint_level(&self,
87+
lint: &'static Lint,
88+
idx: u32,
89+
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>)
8790
-> (Level, LintSource)
8891
{
89-
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx);
92+
let (level, mut src) = self.get_lint_id_level(LintId::of(lint), idx, aux);
9093

9194
// If `level` is none then we actually assume the default level for this
9295
// lint.
@@ -97,7 +100,9 @@ impl LintLevelSets {
97100
// `allow(warnings)` in scope then we want to respect that instead.
98101
if level == Level::Warn {
99102
let (warnings_level, warnings_src) =
100-
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS), idx);
103+
self.get_lint_id_level(LintId::of(lint::builtin::WARNINGS),
104+
idx,
105+
aux);
101106
if let Some(configured_warning_level) = warnings_level {
102107
if configured_warning_level != Level::Warn {
103108
level = configured_warning_level;
@@ -112,9 +117,17 @@ impl LintLevelSets {
112117
return (level, src)
113118
}
114119

115-
fn get_lint_id_level(&self, id: LintId, mut idx: u32)
120+
fn get_lint_id_level(&self,
121+
id: LintId,
122+
mut idx: u32,
123+
aux: Option<&FxHashMap<LintId, (Level, LintSource)>>)
116124
-> (Option<Level>, LintSource)
117125
{
126+
if let Some(specs) = aux {
127+
if let Some(&(level, src)) = specs.get(&id) {
128+
return (Some(level), src)
129+
}
130+
}
118131
loop {
119132
match self.list[idx as usize] {
120133
LintSet::CommandLine { ref specs } => {
@@ -212,21 +225,35 @@ impl<'a> LintLevelsBuilder<'a> {
212225
specs.insert(*id, (level, src));
213226
}
214227
}
228+
229+
_ if !self.warn_about_weird_lints => {}
230+
215231
CheckLintNameResult::Warning(ref msg) => {
216-
if self.warn_about_weird_lints {
217-
self.struct_lint(builtin::RENAMED_AND_REMOVED_LINTS,
218-
Some(li.span.into()),
219-
msg)
220-
.emit();
221-
}
232+
let lint = builtin::RENAMED_AND_REMOVED_LINTS;
233+
let (level, src) = self.sets.get_lint_level(lint,
234+
self.cur,
235+
Some(&specs));
236+
lint::struct_lint_level(self.sess,
237+
lint,
238+
level,
239+
src,
240+
Some(li.span.into()),
241+
msg)
242+
.emit();
222243
}
223244
CheckLintNameResult::NoLint => {
224-
if self.warn_about_weird_lints {
225-
self.struct_lint(builtin::UNKNOWN_LINTS,
226-
Some(li.span.into()),
227-
&format!("unknown lint: `{}`", name))
228-
.emit();
229-
}
245+
let lint = builtin::UNKNOWN_LINTS;
246+
let (level, src) = self.sets.get_lint_level(lint,
247+
self.cur,
248+
Some(&specs));
249+
let msg = format!("unknown lint: `{}`", name);
250+
lint::struct_lint_level(self.sess,
251+
lint,
252+
level,
253+
src,
254+
Some(li.span.into()),
255+
&msg)
256+
.emit();
230257
}
231258
}
232259
}
@@ -236,7 +263,7 @@ impl<'a> LintLevelsBuilder<'a> {
236263
if level == Level::Forbid {
237264
continue
238265
}
239-
let forbid_src = match self.sets.get_lint_id_level(*id, self.cur) {
266+
let forbid_src = match self.sets.get_lint_id_level(*id, self.cur, None) {
240267
(Some(Level::Forbid), src) => src,
241268
_ => continue,
242269
};
@@ -298,7 +325,7 @@ impl<'a> LintLevelsBuilder<'a> {
298325
msg: &str)
299326
-> DiagnosticBuilder<'a>
300327
{
301-
let (level, src) = self.sets.get_lint_level(lint, self.cur);
328+
let (level, src) = self.sets.get_lint_level(lint, self.cur, None);
302329
lint::struct_lint_level(self.sess, lint, level, src, span, msg)
303330
}
304331

@@ -337,7 +364,7 @@ impl LintLevelMap {
337364
-> Option<(Level, LintSource)>
338365
{
339366
self.id_to_set.get(&id).map(|idx| {
340-
self.sets.get_lint_level(lint, *idx)
367+
self.sets.get_lint_level(lint, *idx, None)
341368
})
342369
}
343370
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -D warnings -D unknown-lints
12+
13+
#![allow(unknown_lints)]
14+
#![allow(random_lint_name)]
15+
16+
fn main() {}

0 commit comments

Comments
 (0)