File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -252,7 +252,27 @@ fn strike_through_attributes(
252
252
}
253
253
} ) ;
254
254
255
- strike_attrs. iter ( ) . for_each ( |attr| dec_attrs. insert ( 0 , attr. clone ( ) ) ) ;
255
+ let ( mut derive_attrs, rest_attrs) =
256
+ strike_attrs
257
+ . iter ( )
258
+ . fold ( ( Vec :: new ( ) , Vec :: new ( ) ) ,
259
+ | ( mut der, mut rest) , i| {
260
+ if matches ! ( & i. path[ 0 ] , TokenTree :: Ident ( token) if token == "derive" ) {
261
+ der. push ( i. clone ( ) ) ;
262
+ } else {
263
+ rest. push ( i. clone ( ) ) ;
264
+ }
265
+ ( der, rest)
266
+ } ) ;
267
+
268
+ // place other attrs after the existing ones
269
+ dec_attrs. extend_from_slice ( & rest_attrs[ ..] ) ;
270
+
271
+ // insert derive attrs before attributes
272
+ derive_attrs
273
+ . drain ( ..)
274
+ . for_each ( |attr| dec_attrs. insert ( 0 , attr) ) ;
275
+
256
276
}
257
277
258
278
fn recurse_through_type_list (
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ fn check(nested: proc_macro2::TokenStream, planexpected: proc_macro2::TokenStrea
12
12
#[ test]
13
13
fn strikethrough_derive ( ) {
14
14
let from = quote ! {
15
+ #[ strikethrough[ striked_attr] ]
15
16
#[ strikethrough[ derive( Debug , Default , PartialEq ) ] ]
16
17
#[ gubbel]
17
18
struct Parent {
@@ -22,19 +23,23 @@ fn strikethrough_derive() {
22
23
e: u32 ,
23
24
}
24
25
} ;
26
+
25
27
let out = quote ! {
26
28
#[ derive( Debug , Default , PartialEq ) ]
29
+ #[ striked_attr]
27
30
struct Shared {
28
31
d: i32
29
32
}
30
- #[ gobbel]
31
33
#[ derive( Debug , Default , PartialEq ) ]
34
+ #[ gobbel]
35
+ #[ striked_attr]
32
36
struct A {
33
37
b: Shared ,
34
38
c: Shared ,
35
39
}
36
- #[ gubbel]
37
40
#[ derive( Debug , Default , PartialEq ) ]
41
+ #[ gubbel]
42
+ #[ striked_attr]
38
43
struct Parent {
39
44
a: A ,
40
45
e: u32 ,
You can’t perform that action at this time.
0 commit comments