From 96e1cf3b0693e5724797abd566bd4913be4f6d79 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Thu, 7 May 2015 15:31:20 +0530 Subject: [PATCH] address review comments --- src/librustc/plugin/registry.rs | 13 +++++-------- src/librustc_lint/builtin.rs | 16 +++++++++++----- 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]",