@@ -40,7 +40,7 @@ fn remove_derives_up_to(item: ast::Item, attr_index: usize) -> ast::Item {
40
40
attr. path ( ) . and_then ( |path| path. as_single_segment ( ) ) . and_then ( |seg| seg. name_ref ( ) )
41
41
{
42
42
if name. as_name ( ) == name ! [ derive] {
43
- attr . syntax ( ) . detach ( ) ;
43
+ replace_attr ( & item , & attr ) ;
44
44
}
45
45
}
46
46
}
@@ -54,10 +54,14 @@ fn remove_attr_invoc(item: ast::Item, attr_index: usize) -> ast::Item {
54
54
. attrs ( )
55
55
. nth ( attr_index)
56
56
. unwrap_or_else ( || panic ! ( "cannot find attribute #{}" , attr_index) ) ;
57
+ replace_attr ( & item, & attr) ;
58
+ item
59
+ }
60
+
61
+ fn replace_attr ( item : & ast:: Item , attr : & ast:: Attr ) {
57
62
let syntax_index = attr. syntax ( ) . index ( ) ;
58
63
let ws = make:: tokens:: whitespace ( & " " . repeat ( u32:: from ( attr. syntax ( ) . text ( ) . len ( ) ) as usize ) ) ;
59
64
item. syntax ( ) . splice_children ( syntax_index..syntax_index + 1 , vec ! [ ws. into( ) ] ) ;
60
- item
61
65
}
62
66
63
67
#[ cfg( test) ]
@@ -78,7 +82,9 @@ mod tests {
78
82
assert_eq ! ( items. len( ) , 1 ) ;
79
83
80
84
let item = remove_derives_up_to ( items. pop ( ) . unwrap ( ) , attr) ;
81
- expect. assert_eq ( & item. to_string ( ) ) ;
85
+ let res: String =
86
+ item. syntax ( ) . children_with_tokens ( ) . map ( |e| format ! ( "{:?}\n " , e) ) . collect ( ) ;
87
+ expect. assert_eq ( & res) ;
82
88
}
83
89
84
90
#[ test]
@@ -95,13 +101,20 @@ struct A {
95
101
}
96
102
"# ,
97
103
expect ! [ [ r#"
98
- #[allow(unused)]
99
-
100
-
101
- #[derive(Clone)]
102
- struct A {
103
- bar: u32
104
- }"# ] ] ,
104
+
105
+
106
+
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+
117
+ "# ] ] ,
105
118
) ;
106
119
}
107
120
}
0 commit comments