Skip to content

rustc: Fix unknown_lints next to an unknown lint #43841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 46 additions & 19 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
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
// lint.
Expand All @@ -97,7 +100,9 @@ impl LintLevelSets {
// `allow(warnings)` in scope then we want to respect that instead.
if level == Level::Warn {
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 configured_warning_level != Level::Warn {
level = configured_warning_level;
Expand All @@ -112,9 +117,17 @@ impl LintLevelSets {
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)
{
if let Some(specs) = aux {
if let Some(&(level, src)) = specs.get(&id) {
return (Some(level), src)
}
}
loop {
match self.list[idx as usize] {
LintSet::CommandLine { ref specs } => {
Expand Down Expand Up @@ -212,21 +225,35 @@ impl<'a> LintLevelsBuilder<'a> {
specs.insert(*id, (level, src));
}
}

_ if !self.warn_about_weird_lints => {}

CheckLintNameResult::Warning(ref msg) => {
if self.warn_about_weird_lints {
self.struct_lint(builtin::RENAMED_AND_REMOVED_LINTS,
Some(li.span.into()),
msg)
.emit();
}
let 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()),
msg)
.emit();
}
CheckLintNameResult::NoLint => {
if self.warn_about_weird_lints {
self.struct_lint(builtin::UNKNOWN_LINTS,
Some(li.span.into()),
&format!("unknown lint: `{}`", name))
.emit();
}
let 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()),
&msg)
.emit();
}
}
}
Expand All @@ -236,7 +263,7 @@ impl<'a> LintLevelsBuilder<'a> {
if level == Level::Forbid {
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,
_ => continue,
};
Expand Down Expand Up @@ -298,7 +325,7 @@ impl<'a> LintLevelsBuilder<'a> {
msg: &str)
-> 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)
}

Expand Down Expand Up @@ -337,7 +364,7 @@ impl LintLevelMap {
-> Option<(Level, LintSource)>
{
self.id_to_set.get(&id).map(|idx| {
self.sets.get_lint_level(lint, *idx)
self.sets.get_lint_level(lint, *idx, None)
})
}
}
16 changes: 16 additions & 0 deletions src/test/run-pass/lint-unknown-lints-at-crate-level.rs
Original file line number Diff line number Diff line change
@@ -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() {}