address review comments
This commit is contained in:
parent
d46eef9cf3
commit
96e1cf3b06
@ -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));
|
||||
}
|
||||
|
@ -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]",
|
||||
|
Loading…
x
Reference in New Issue
Block a user