about summary refs log tree commit diff
diff options
context:
space:
mode:
authorflip1995 <9744647+flip1995@users.noreply.github.com>2018-07-04 14:25:33 +0200
committerflip1995 <9744647+flip1995@users.noreply.github.com>2018-07-04 14:28:44 +0200
commitc3949009adf7e8a039a1f467cbc6e6b5cf993303 (patch)
tree2fe55c9bfbfd0963dcaea3a0ad735cbbd1f4e294
parenta9634fcd013a31842e551ba30c25e389a5d67bbd (diff)
downloadrust-c3949009adf7e8a039a1f467cbc6e6b5cf993303.tar.gz
rust-c3949009adf7e8a039a1f467cbc6e6b5cf993303.zip
Improving span of unknown lint tool error message
-rw-r--r--src/librustc/lint/levels.rs8
-rw-r--r--src/libsyntax/attr/mod.rs14
-rw-r--r--src/test/compile-fail/unknown-lint-tool-name.rs4
-rw-r--r--src/test/ui/tool_lints.rs15
-rw-r--r--src/test/ui/tool_lints.stderr9
5 files changed, 38 insertions, 12 deletions
diff --git a/src/librustc/lint/levels.rs b/src/librustc/lint/levels.rs
index 6761b7b7492..5bf15b10715 100644
--- a/src/librustc/lint/levels.rs
+++ b/src/librustc/lint/levels.rs
@@ -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
                         );
                     }
diff --git a/src/libsyntax/attr/mod.rs b/src/libsyntax/attr/mod.rs
index f8db62083c7..d746ac3c577 100644
--- a/src/libsyntax/attr/mod.rs
+++ b/src/libsyntax/attr/mod.rs
@@ -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
+        }
     }
 }
 
diff --git a/src/test/compile-fail/unknown-lint-tool-name.rs b/src/test/compile-fail/unknown-lint-tool-name.rs
index 173803d6030..78b736edceb 100644
--- a/src/test/compile-fail/unknown-lint-tool-name.rs
+++ b/src/test/compile-fail/unknown-lint-tool-name.rs
@@ -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() {}
diff --git a/src/test/ui/tool_lints.rs b/src/test/ui/tool_lints.rs
new file mode 100644
index 00000000000..71f90b17c18
--- /dev/null
+++ b/src/test/ui/tool_lints.rs
@@ -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() {}
diff --git a/src/test/ui/tool_lints.stderr b/src/test/ui/tool_lints.stderr
new file mode 100644
index 00000000000..16468df7370
--- /dev/null
+++ b/src/test/ui/tool_lints.stderr
@@ -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`.