@@ -64,6 +64,7 @@ use crate::parser::{ArgParser, MetaItemParser, PathParser};
6464use crate :: session_diagnostics:: {
6565 AttributeParseError , AttributeParseErrorReason , InvalidTarget , UnknownMetaItem ,
6666} ;
67+ use itertools:: Itertools ;
6768
6869type GroupType < S > = LazyLock < GroupTypeInner < S > > ;
6970
@@ -916,31 +917,28 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
916917 match accept. allowed_targets . is_allowed ( target) {
917918 AllowedResult :: Allowed => { }
918919 AllowedResult :: Warn => {
920+ let allowed_targets = accept. allowed_targets . allowed_targets ( ) ;
919921 emit_lint ( AttributeLint {
920922 id : target_id,
921923 span : attr. span ,
922924 kind : AttributeLintKind :: InvalidTarget {
923925 name : parts[ 0 ] ,
924926 article : target. article ( ) ,
925927 target : target. name ( ) ,
928+ only : if allowed_targets. len ( ) == 1 { "only " } else { "" } ,
929+ applied : allowed_targets_applied ( & allowed_targets, target)
926930 } ,
927931 } ) ;
928932 }
929933 AllowedResult :: Error => {
930934 let allowed_targets = accept. allowed_targets . allowed_targets ( ) ;
931-
932-
933935 self . dcx ( ) . emit_err ( InvalidTarget {
934936 span : attr. span ,
935937 name : parts[ 0 ] ,
936938 article : target. article ( ) ,
937939 target : target. name ( ) ,
938940 only : if allowed_targets. len ( ) == 1 { "only " } else { "" } ,
939- applied : if allowed_targets. len ( ) == 1 {
940- target. name ( )
941- } else {
942- "..."
943- } . to_string ( )
941+ applied : allowed_targets_applied ( & allowed_targets, target)
944942 } ) ;
945943 }
946944 }
@@ -1031,6 +1029,13 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
10311029 }
10321030}
10331031
1032+ pub ( crate ) fn allowed_targets_applied ( allowed_targets : & [ Target ] , target : Target ) -> String {
1033+ if allowed_targets. len ( ) == 1 {
1034+ return format ! ( "{} {}" , allowed_targets[ 0 ] . article( ) , allowed_targets[ 0 ] . name( ) )
1035+ }
1036+ allowed_targets. iter ( ) . map ( |t| t. name ( ) ) . join ( ", " )
1037+ }
1038+
10341039/// Parse a single integer.
10351040///
10361041/// Used by attributes that take a single integer as argument, such as
0 commit comments