Improving span of unknown lint tool error message

This commit is contained in:
flip1995 2018-07-04 14:25:33 +02:00
parent a9634fcd01
commit c3949009ad
No known key found for this signature in database
GPG Key ID: 9F184E1164831181
5 changed files with 38 additions and 12 deletions

View File

@ -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",
@ -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
);
}

View File

@ -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 {
@ -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
}
}
}

View File

@ -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
src/test/ui/tool_lints.rs Normal file
View File

@ -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() {}

View File

@ -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`.