]> git.lizzy.rs Git - rust.git/commitdiff
Improving span of unknown lint tool error message
authorflip1995 <9744647+flip1995@users.noreply.github.com>
Wed, 4 Jul 2018 12:25:33 +0000 (14:25 +0200)
committerflip1995 <9744647+flip1995@users.noreply.github.com>
Wed, 4 Jul 2018 12:28:44 +0000 (14:28 +0200)
src/librustc/lint/levels.rs
src/libsyntax/attr/mod.rs
src/test/compile-fail/unknown-lint-tool-name.rs
src/test/ui/tool_lints.rs [new file with mode: 0644]
src/test/ui/tool_lints.stderr [new file with mode: 0644]

index 6761b7b74924fb5f7b779f13b686e33faf415866..5bf15b10715c4a68ddeb7fc76b1b6410ee61b550 100644 (file)
@@ -222,7 +222,7 @@ pub fn push(&mut self, attrs: &[ast::Attribute]) -> BuilderPush {
                         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 @@ pub fn push(&mut self, attrs: &[ast::Attribute]) -> BuilderPush {
                                                                 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
                         );
                     }
index f8db62083c7fd8dd89a0f476ba44eb37d020a68b..d746ac3c5771bb19f9c15526c1a4c37f3c504ae4 100644 (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 @@ pub fn is_meta_item_list(&self) -> bool {
         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
+        }
     }
 }
 
index 173803d6030d382a383aa9136ea3aa702eea7dac..78b736edcebe6e0699beae6d7deb7c789518718a 100644 (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() {}
diff --git a/src/test/ui/tool_lints.rs b/src/test/ui/tool_lints.rs
new file mode 100644 (file)
index 0000000..71f90b1
--- /dev/null
@@ -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 (file)
index 0000000..16468df
--- /dev/null
@@ -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`.