@@ -27,7 +27,7 @@ impl GenericParamsOwnerEdit for ast::Fn {
27
27
} else {
28
28
Position :: last_child_of ( self . syntax ( ) . clone ( ) )
29
29
} ;
30
- create_where_clause ( position)
30
+ create_where_clause ( position, true )
31
31
}
32
32
self . where_clause ( ) . unwrap ( )
33
33
}
@@ -36,16 +36,31 @@ impl GenericParamsOwnerEdit for ast::Fn {
36
36
impl GenericParamsOwnerEdit for ast:: Impl {
37
37
fn get_or_create_where_clause ( & self ) -> WhereClause {
38
38
if self . where_clause ( ) . is_none ( ) {
39
- let position = if let Some ( ty ) = self . self_ty ( ) {
40
- Position :: after ( ty . syntax ( ) . clone ( ) )
39
+ let position = if let Some ( items ) = self . assoc_item_list ( ) {
40
+ Position :: before ( items . syntax ( ) . clone ( ) )
41
41
} else {
42
42
Position :: last_child_of ( self . syntax ( ) . clone ( ) )
43
43
} ;
44
- create_where_clause ( position)
44
+ create_where_clause ( position, false )
45
45
}
46
46
self . where_clause ( ) . unwrap ( )
47
47
}
48
48
}
49
+
50
+ impl GenericParamsOwnerEdit for ast:: Trait {
51
+ fn get_or_create_where_clause ( & self ) -> WhereClause {
52
+ if self . where_clause ( ) . is_none ( ) {
53
+ let position = if let Some ( items) = self . assoc_item_list ( ) {
54
+ Position :: before ( items. syntax ( ) . clone ( ) )
55
+ } else {
56
+ Position :: last_child_of ( self . syntax ( ) . clone ( ) )
57
+ } ;
58
+ create_where_clause ( position, false )
59
+ }
60
+ self . where_clause ( ) . unwrap ( )
61
+ }
62
+ }
63
+
49
64
impl GenericParamsOwnerEdit for ast:: Struct {
50
65
fn get_or_create_where_clause ( & self ) -> WhereClause {
51
66
if self . where_clause ( ) . is_none ( ) {
@@ -62,17 +77,36 @@ impl GenericParamsOwnerEdit for ast::Struct {
62
77
} else {
63
78
Position :: last_child_of ( self . syntax ( ) . clone ( ) )
64
79
} ;
65
- create_where_clause ( position)
80
+ create_where_clause ( position, true )
81
+ }
82
+ self . where_clause ( ) . unwrap ( )
83
+ }
84
+ }
85
+
86
+ impl GenericParamsOwnerEdit for ast:: Enum {
87
+ fn get_or_create_where_clause ( & self ) -> WhereClause {
88
+ if self . where_clause ( ) . is_none ( ) {
89
+ let position = if let Some ( gpl) = self . generic_param_list ( ) {
90
+ Position :: after ( gpl. syntax ( ) . clone ( ) )
91
+ } else if let Some ( name) = self . name ( ) {
92
+ Position :: after ( name. syntax ( ) . clone ( ) )
93
+ } else {
94
+ Position :: last_child_of ( self . syntax ( ) . clone ( ) )
95
+ } ;
96
+ create_where_clause ( position, true )
66
97
}
67
98
self . where_clause ( ) . unwrap ( )
68
99
}
69
100
}
70
101
71
- fn create_where_clause ( position : Position ) {
72
- let elements = vec ! [
73
- make:: tokens:: single_space( ) . into( ) ,
74
- make:: where_clause( empty( ) ) . clone_for_update( ) . syntax( ) . clone( ) . into( ) ,
75
- ] ;
102
+ fn create_where_clause ( position : Position , after : bool ) {
103
+ let mut elements = vec ! [ make:: where_clause( empty( ) ) . clone_for_update( ) . syntax( ) . clone( ) . into( ) ] ;
104
+ let ws = make:: tokens:: single_space ( ) . into ( ) ;
105
+ if after {
106
+ elements. insert ( 0 , ws)
107
+ } else {
108
+ elements. push ( ws)
109
+ }
76
110
ted:: insert_all ( position, elements) ;
77
111
}
78
112
0 commit comments