@@ -21,6 +21,7 @@ enum TypeOrConst {
21
21
}
22
22
23
23
type LifetimeName = String ;
24
+ type DefaultedParam = Either < hir:: TypeParam , hir:: ConstParam > ;
24
25
25
26
/// `PathTransform` substitutes path in SyntaxNodes in bulk.
26
27
///
@@ -115,7 +116,7 @@ impl<'a> PathTransform<'a> {
115
116
} ;
116
117
let mut type_substs: FxHashMap < hir:: TypeParam , ast:: Type > = Default :: default ( ) ;
117
118
let mut const_substs: FxHashMap < hir:: ConstParam , SyntaxNode > = Default :: default ( ) ;
118
- let mut default_types : Vec < hir :: TypeParam > = Default :: default ( ) ;
119
+ let mut defaulted_params : Vec < DefaultedParam > = Default :: default ( ) ;
119
120
self . generic_def
120
121
. into_iter ( )
121
122
. flat_map ( |it| it. type_params ( db) )
@@ -139,7 +140,7 @@ impl<'a> PathTransform<'a> {
139
140
& default. display_source_code ( db, source_module. into ( ) , false ) . ok ( )
140
141
{
141
142
type_substs. insert ( k, ast:: make:: ty ( default) . clone_for_update ( ) ) ;
142
- default_types . push ( k ) ;
143
+ defaulted_params . push ( Either :: Left ( k ) ) ;
143
144
}
144
145
}
145
146
}
@@ -162,7 +163,7 @@ impl<'a> PathTransform<'a> {
162
163
if let Some ( default) = k. default ( db) {
163
164
if let Some ( default) = ast:: make:: expr_const_value ( & default) . expr ( ) {
164
165
const_substs. insert ( k, default. syntax ( ) . clone_for_update ( ) ) ;
165
- // FIXME: transform the default value
166
+ defaulted_params . push ( Either :: Right ( k ) ) ;
166
167
}
167
168
}
168
169
}
@@ -182,7 +183,7 @@ impl<'a> PathTransform<'a> {
182
183
target_module,
183
184
source_scope : self . source_scope ,
184
185
} ;
185
- ctx. transform_default_type_substs ( default_types ) ;
186
+ ctx. transform_default_values ( defaulted_params ) ;
186
187
ctx
187
188
}
188
189
}
@@ -219,13 +220,19 @@ impl Ctx<'_> {
219
220
} ) ;
220
221
}
221
222
222
- fn transform_default_type_substs ( & self , default_types : Vec < hir:: TypeParam > ) {
223
- for k in default_types {
224
- let v = self . type_substs . get ( & k) . unwrap ( ) ;
223
+ fn transform_default_values ( & self , defaulted_params : Vec < DefaultedParam > ) {
224
+ // By now the default values are simply copied from where they are declared
225
+ // and should be transformed. As any value is allowed to refer to previous
226
+ // generic (both type and const) parameters, they should be all iterated left-to-right.
227
+ for param in defaulted_params {
228
+ let value = match param {
229
+ Either :: Left ( k) => self . type_substs . get ( & k) . unwrap ( ) . syntax ( ) ,
230
+ Either :: Right ( k) => self . const_substs . get ( & k) . unwrap ( ) ,
231
+ } ;
225
232
// `transform_path` may update a node's parent and that would break the
226
233
// tree traversal. Thus all paths in the tree are collected into a vec
227
234
// so that such operation is safe.
228
- let paths = postorder ( & v . syntax ( ) ) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
235
+ let paths = postorder ( value ) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
229
236
for path in paths {
230
237
self . transform_path ( path) ;
231
238
}
0 commit comments