@@ -57,6 +57,7 @@ use crate::ir::var::Var;
57
57
58
58
use proc_macro2:: { Ident , Span , TokenStream } ;
59
59
use quote:: { ToTokens , TokenStreamExt } ;
60
+ use syn:: { parse_quote, Attribute } ;
60
61
61
62
use crate :: { Entry , HashMap , HashSet } ;
62
63
use std:: borrow:: Cow ;
@@ -1066,28 +1067,46 @@ impl CodeGenerator for Type {
1066
1067
if let Some ( inner_attrs) =
1067
1068
result. get_attributes ( inner_item. id ( ) )
1068
1069
{
1069
- attrs. extend ( inner_attrs. iter ( ) . cloned ( ) ) ;
1070
+ // Only apply attributes through type aliases when they are relevant to compilation
1071
+ attrs. extend (
1072
+ parse_tokens ( inner_attrs)
1073
+ . into_iter ( )
1074
+ . map ( |attr| parse_quote ! { #attr } )
1075
+ . filter_map ( |attr : Attribute |{
1076
+ if attr. path ( ) . is_ident ( "cfg" ) || attr. path ( ) . is_ident ( "link" ) {
1077
+ Some ( attr. to_token_stream ( ) . to_string ( ) )
1078
+ } else {
1079
+ None
1080
+ }
1081
+ } )
1082
+ ) ;
1070
1083
}
1071
1084
1085
+ // Apply attributes through annotations directly
1072
1086
attrs. extend ( item. annotations ( ) . attributes ( ) . iter ( ) . cloned ( ) ) ;
1073
1087
1088
+ // Apply comments to attributes
1074
1089
if let Some ( comment) = item. comment ( ctx) {
1075
1090
attrs. insert ( attributes:: doc ( comment) . to_string ( ) ) ;
1076
1091
}
1077
1092
1093
+ // Allow the callbacks to process our attributes
1078
1094
ctx. options ( ) . for_each_callback_mut ( |cb| {
1079
1095
cb. process_attributes (
1080
1096
& AttributeInfo {
1081
1097
name : & name,
1082
- // TODO: Perhaps add a TypeAlias variant and provide the alias_style / AliasVariation here as well as the affected item
1098
+ // FIXME: Introduce a TypeAlias variant with extra information similar
1099
+ // to DiscoveredItem::Alias, indicating this is merely an alias
1100
+ // and not a new type definition.
1083
1101
kind : AttributeItemKind :: Struct ,
1084
1102
} ,
1085
1103
& mut attrs,
1086
1104
) ;
1087
1105
} ) ;
1106
+
1107
+ // Store the final attributes of this item
1088
1108
result. set_attributes ( item. id ( ) , attrs. clone ( ) ) ;
1089
1109
1090
- // TODO: Only apply attributes relevant to conditional compilation
1091
1110
let attrs = parse_tokens ( attrs) ;
1092
1111
let mut tokens = quote ! {
1093
1112
#( #attrs ) *
0 commit comments