@@ -46,11 +46,15 @@ pub struct PalletAttr {
46
46
typ : PalletAttrType ,
47
47
}
48
48
49
- fn get_first_item_pallet_attr < Attr > ( item : & syn:: ImplItemType ) -> syn:: Result < Option < Attr > >
50
- where
51
- Attr : syn:: parse:: Parse ,
52
- {
53
- item. attrs . get ( 0 ) . map ( |a| syn:: parse2 ( a. into_token_stream ( ) ) ) . transpose ( )
49
+ fn is_runtime_type ( item : & syn:: ImplItemType ) -> bool {
50
+ item. attrs . iter ( ) . any ( |attr| {
51
+ if let Ok ( PalletAttr { typ : PalletAttrType :: RuntimeType ( _) , .. } ) =
52
+ parse2 :: < PalletAttr > ( attr. into_token_stream ( ) )
53
+ {
54
+ return true
55
+ }
56
+ false
57
+ } )
54
58
}
55
59
56
60
#[ derive( Parse , Debug ) ]
@@ -132,10 +136,7 @@ fn combine_impls(
132
136
return None
133
137
}
134
138
if let ImplItem :: Type ( typ) = item. clone ( ) {
135
- let mut typ = typ. clone ( ) ;
136
- if let Ok ( Some ( PalletAttr { typ : PalletAttrType :: RuntimeType ( _) , .. } ) ) =
137
- get_first_item_pallet_attr :: < PalletAttr > ( & mut typ)
138
- {
139
+ if is_runtime_type ( & typ) {
139
140
let item: ImplItem = if inject_runtime_types {
140
141
parse_quote ! {
141
142
type #ident = #ident;
@@ -227,3 +228,25 @@ fn test_derive_impl_attr_args_parsing() {
227
228
assert ! ( parse2:: <DeriveImplAttrArgs >( quote!( ) ) . is_err( ) ) ;
228
229
assert ! ( parse2:: <DeriveImplAttrArgs >( quote!( Config Config ) ) . is_err( ) ) ;
229
230
}
231
+
232
+ #[ test]
233
+ fn test_runtime_type_with_doc ( ) {
234
+ trait TestTrait {
235
+ type Test ;
236
+ }
237
+ #[ allow( unused) ]
238
+ struct TestStruct ;
239
+ let p = parse2 :: < ItemImpl > ( quote ! (
240
+ impl TestTrait for TestStruct {
241
+ /// Some doc
242
+ #[ inject_runtime_type]
243
+ type Test = u32 ;
244
+ }
245
+ ) )
246
+ . unwrap ( ) ;
247
+ for item in p. items {
248
+ if let ImplItem :: Type ( typ) = item {
249
+ assert_eq ! ( is_runtime_type( & typ) , true ) ;
250
+ }
251
+ }
252
+ }
0 commit comments