@@ -651,21 +651,32 @@ pub(crate) enum AllowedTargets {
651651 AllowListWarnRest ( & ' static [ MaybeWarn ] ) ,
652652}
653653
654+ pub ( crate ) enum AllowedResult {
655+ Allowed ,
656+ Warn ,
657+ Error ,
658+ }
659+
654660impl AllowedTargets {
655- pub ( crate ) fn is_allowed ( & self , target : Target ) -> bool {
661+ pub ( crate ) fn is_allowed ( & self , target : Target ) -> AllowedResult {
656662 match self {
657- AllowedTargets :: AllowAll => true ,
658- AllowedTargets :: AllowList ( list) | AllowedTargets :: AllowListWarnRest ( list) => {
659- list. contains ( & Allow ( target) )
663+ AllowedTargets :: AllowAll => AllowedResult :: Allowed ,
664+ AllowedTargets :: AllowList ( list) => {
665+ if list. contains ( & Allow ( target) ) {
666+ AllowedResult :: Allowed
667+ } else if list. contains ( & Warn ( target) ) {
668+ AllowedResult :: Warn
669+ } else {
670+ AllowedResult :: Error
671+ }
672+ }
673+ AllowedTargets :: AllowListWarnRest ( list) => {
674+ if list. contains ( & Allow ( target) ) {
675+ AllowedResult :: Allowed
676+ } else {
677+ AllowedResult :: Warn
678+ }
660679 }
661- }
662- }
663-
664- pub ( crate ) fn is_warn ( & self , target : Target ) -> bool {
665- match self {
666- AllowedTargets :: AllowAll => false ,
667- AllowedTargets :: AllowList ( list) => list. contains ( & Warn ( target) ) ,
668- AllowedTargets :: AllowListWarnRest ( list) => !list. contains ( & Allow ( target) ) ,
669680 }
670681 }
671682}
@@ -884,17 +895,20 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
884895
885896 ( accept. accept_fn ) ( & mut cx, args) ;
886897
887- if self . stage . should_emit ( ) . should_emit ( )
888- && !accept. allowed_targets . is_allowed ( target)
889- && !accept. allowed_targets . is_warn ( target)
890- {
891- self . dcx ( ) . span_delayed_bug (
892- n. item . span ( ) ,
893- format ! (
894- "{:?} target {target:?} not allowed {:?}" ,
895- parts, accept. allowed_targets
896- ) ,
897- ) ;
898+ if self . stage . should_emit ( ) . should_emit ( ) {
899+ match accept. allowed_targets . is_allowed ( target) {
900+ AllowedResult :: Allowed => { }
901+ AllowedResult :: Warn => {
902+ emit_lint ( AttributeLint {
903+ id : target_id,
904+ span : n. item . span ( ) ,
905+ kind : AttributeLintKind :: InvalidTarget { } ,
906+ } ) ;
907+ }
908+ AllowedResult :: Error => {
909+ self . dcx ( ) . struct_span_err ( n. item . span ( ) , "this attribute is not allowed on this target" ) . emit ( ) ;
910+ }
911+ }
898912 }
899913 } else {
900914 // If we're here, we must be compiling a tool attribute... Or someone
0 commit comments