File tree 2 files changed +16
-13
lines changed
2 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -139,17 +139,14 @@ impl<'a> Registry<'a> {
139
139
140
140
/// Register an attribute with an attribute type
141
141
///
142
- /// Registered attributes will bypass the `custom_attribute` feature gate
143
- ///
142
+ /// Registered attributes will bypass the `custom_attribute` feature gate.
144
143
/// `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.
148
145
pub fn register_attribute ( & mut self , name : String , ty : AttributeType ) {
149
146
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") ;
153
150
}
154
151
self . attributes . push ( ( name, ty) ) ;
155
152
}
Original file line number Diff line number Diff line change @@ -653,11 +653,17 @@ impl LintPass for UnusedAttributes {
653
653
654
654
if !attr:: is_used ( attr) {
655
655
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 {
661
667
let msg = match attr. node . style {
662
668
ast:: AttrOuter => "crate-level attribute should be an inner \
663
669
attribute: add an exclamation mark: #![foo]",
You can’t perform that action at this time.
0 commit comments