about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc/plugin/registry.rs13
-rw-r--r--src/librustc_lint/builtin.rs16
2 files changed, 16 insertions, 13 deletions
diff --git a/src/librustc/plugin/registry.rs b/src/librustc/plugin/registry.rs
index c85b30c811c..d532ad38d04 100644
--- a/src/librustc/plugin/registry.rs
+++ b/src/librustc/plugin/registry.rs
@@ -139,17 +139,14 @@ impl<'a> Registry<'a> {
 
     /// Register an attribute with an attribute type
     ///
-    /// Registered attributes will bypass the `custom_attribute` feature gate
-    ///
+    /// Registered attributes will bypass the `custom_attribute` feature gate.
     /// `Whitelisted` attributes will additionally not trigger the `unused_attribute`
-    /// lint
-    ///
-    /// `CrateLevel` attributes will not be allowed on anything other than a crate
+    /// lint. `CrateLevel` attributes will not be allowed on anything other than a crate.
     pub fn register_attribute(&mut self, name: String, ty: AttributeType) {
         if let AttributeType::Gated(..) = ty {
-            self.sess.err("plugin tried to register a gated attribute. \
-                           Only `Normal`, `Whitelisted`, and `CrateLevel` \
-                           attributes are allowed");
+            self.sess.span_err(self.krate_span, "plugin tried to register a gated \
+                                                 attribute. Only `Normal`, `Whitelisted`, \
+                                                 and `CrateLevel` attributes are allowed");
         }
         self.attributes.push((name, ty));
     }
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs
index 9242274a7a3..27c70213151 100644
--- a/src/librustc_lint/builtin.rs
+++ b/src/librustc_lint/builtin.rs
@@ -653,11 +653,17 @@ impl LintPass for UnusedAttributes {
 
         if !attr::is_used(attr) {
             cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
-            if KNOWN_ATTRIBUTES.contains(&(&attr.name(), AttributeType::CrateLevel)) ||
-               plugin_attributes.iter()
-                                .find(|&&(ref x, t)| &*attr.name() == &*x &&
-                                                     AttributeType::CrateLevel == t)
-                                .is_some() {
+            // Is it a builtin attribute that must be used at the crate level?
+            let known_crate = KNOWN_ATTRIBUTES.contains(&(&attr.name(),
+                                                          AttributeType::CrateLevel));
+            // Has a plugin registered this attribute as one which must be used at
+            // the crate level?
+            let plugin_crate = plugin_attributes.iter()
+                                                .find(|&&(ref x, t)| {
+                                                        &*attr.name() == &*x &&
+                                                        AttributeType::CrateLevel == t
+                                                    }).is_some();
+            if  known_crate || plugin_crate {
                 let msg = match attr.node.style {
                     ast::AttrOuter => "crate-level attribute should be an inner \
                                        attribute: add an exclamation mark: #![foo]",