Skip to content

Commit

Permalink
Improving span of unknown lint tool error message
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Jul 4, 2018
1 parent a9634fc commit c394900
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/librustc/lint/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl<'a> LintLevelsBuilder<'a> {
continue
}
};
if word.is_scoped() {
if let Some(lint_tool) = word.is_scoped() {
if !self.sess.features_untracked().tool_lints {
feature_gate::emit_feature_err(&sess.parse_sess,
"tool_lints",
Expand All @@ -232,12 +232,12 @@ impl<'a> LintLevelsBuilder<'a> {
word.ident));
}

if !attr::is_known_lint_tool(word) {
if !attr::is_known_lint_tool(lint_tool) {
span_err!(
sess,
word.span,
lint_tool.span,
E0710,
"an unknown tool name found in scoped lint: `{}`.",
"an unknown tool name found in scoped lint: `{}`",
word.ident
);
}
Expand Down
14 changes: 8 additions & 6 deletions src/libsyntax/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,8 @@ pub fn is_known_tool(attr: &Attribute) -> bool {
RUST_KNOWN_TOOL.contains(&tool_name.as_str().as_ref())
}

pub fn is_known_lint_tool(m_item: &MetaItem) -> bool {
let tool_name =
m_item.ident.segments.iter().next().expect("empty path in meta item").ident.name;
RUST_KNOWN_LINT_TOOL.contains(&tool_name.as_str().as_ref())
pub fn is_known_lint_tool(m_item: Ident) -> bool {
RUST_KNOWN_LINT_TOOL.contains(&m_item.as_str().as_ref())
}

impl NestedMetaItem {
Expand Down Expand Up @@ -298,8 +296,12 @@ impl MetaItem {
self.meta_item_list().is_some()
}

pub fn is_scoped(&self) -> bool {
self.ident.segments.len() > 1
pub fn is_scoped(&self) -> Option<Ident> {
if self.ident.segments.len() > 1 {
Some(self.ident.segments[0].ident)
} else {
None
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/unknown-lint-tool-name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#![feature(tool_lints)]

#![deny(foo::bar)] //~ ERROR an unknown tool name found in scoped lint: `foo::bar`.
#![deny(foo::bar)] //~ ERROR an unknown tool name found in scoped lint: `foo::bar`

#[allow(foo::bar)] //~ ERROR an unknown tool name found in scoped lint: `foo::bar`.
#[allow(foo::bar)] //~ ERROR an unknown tool name found in scoped lint: `foo::bar`
fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/tool_lints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2018 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.

#![feature(tool_lints)]

#[warn(foo::bar)]
//~^ ERROR an unknown tool name found in scoped lint: `foo::bar`
fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/tool_lints.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0710]: an unknown tool name found in scoped lint: `foo::bar`
--> $DIR/tool_lints.rs:13:8
|
LL | #[warn(foo::bar)]
| ^^^

error: aborting due to previous error

For more information about this error, try `rustc --explain E0710`.

0 comments on commit c394900

Please sign in to comment.