Skip to content

Commit 96e1cf3

Browse files
committed
address review comments
1 parent d46eef9 commit 96e1cf3

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/librustc/plugin/registry.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -139,17 +139,14 @@ impl<'a> Registry<'a> {
139139

140140
/// Register an attribute with an attribute type
141141
///
142-
/// Registered attributes will bypass the `custom_attribute` feature gate
143-
///
142+
/// Registered attributes will bypass the `custom_attribute` feature gate.
144143
/// `Whitelisted` attributes will additionally not trigger the `unused_attribute`
145-
/// lint
146-
///
147-
/// `CrateLevel` attributes will not be allowed on anything other than a crate
144+
/// lint. `CrateLevel` attributes will not be allowed on anything other than a crate.
148145
pub fn register_attribute(&mut self, name: String, ty: AttributeType) {
149146
if let AttributeType::Gated(..) = ty {
150-
self.sess.err("plugin tried to register a gated attribute. \
151-
Only `Normal`, `Whitelisted`, and `CrateLevel` \
152-
attributes are allowed");
147+
self.sess.span_err(self.krate_span, "plugin tried to register a gated \
148+
attribute. Only `Normal`, `Whitelisted`, \
149+
and `CrateLevel` attributes are allowed");
153150
}
154151
self.attributes.push((name, ty));
155152
}

src/librustc_lint/builtin.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -653,11 +653,17 @@ impl LintPass for UnusedAttributes {
653653

654654
if !attr::is_used(attr) {
655655
cx.span_lint(UNUSED_ATTRIBUTES, attr.span, "unused attribute");
656-
if KNOWN_ATTRIBUTES.contains(&(&attr.name(), AttributeType::CrateLevel)) ||
657-
plugin_attributes.iter()
658-
.find(|&&(ref x, t)| &*attr.name() == &*x &&
659-
AttributeType::CrateLevel == t)
660-
.is_some() {
656+
// Is it a builtin attribute that must be used at the crate level?
657+
let known_crate = KNOWN_ATTRIBUTES.contains(&(&attr.name(),
658+
AttributeType::CrateLevel));
659+
// Has a plugin registered this attribute as one which must be used at
660+
// the crate level?
661+
let plugin_crate = plugin_attributes.iter()
662+
.find(|&&(ref x, t)| {
663+
&*attr.name() == &*x &&
664+
AttributeType::CrateLevel == t
665+
}).is_some();
666+
if known_crate || plugin_crate {
661667
let msg = match attr.node.style {
662668
ast::AttrOuter => "crate-level attribute should be an inner \
663669
attribute: add an exclamation mark: #![foo]",

0 commit comments

Comments
 (0)