3
3
use crate :: helpers:: mod_path_to_ast;
4
4
use either:: Either ;
5
5
use hir:: { AsAssocItem , HirDisplay , ModuleDef , SemanticsScope } ;
6
+ use itertools:: Itertools ;
6
7
use rustc_hash:: FxHashMap ;
7
8
use syntax:: {
8
9
ast:: { self , make, AstNode } ,
@@ -227,24 +228,28 @@ struct Ctx<'a> {
227
228
same_self_type : bool ,
228
229
}
229
230
230
- fn postorder ( item : & SyntaxNode ) -> impl Iterator < Item = SyntaxNode > {
231
- item. preorder ( ) . filter_map ( |event| match event {
232
- syntax:: WalkEvent :: Enter ( _) => None ,
233
- syntax:: WalkEvent :: Leave ( node) => Some ( node) ,
234
- } )
231
+ fn preorder_rev ( item : & SyntaxNode ) -> impl Iterator < Item = SyntaxNode > {
232
+ let x = item
233
+ . preorder ( )
234
+ . filter_map ( |event| match event {
235
+ syntax:: WalkEvent :: Enter ( node) => Some ( node) ,
236
+ syntax:: WalkEvent :: Leave ( _) => None ,
237
+ } )
238
+ . collect_vec ( ) ;
239
+ x. into_iter ( ) . rev ( )
235
240
}
236
241
237
242
impl Ctx < ' _ > {
238
243
fn apply ( & self , item : & SyntaxNode ) {
239
244
// `transform_path` may update a node's parent and that would break the
240
245
// tree traversal. Thus all paths in the tree are collected into a vec
241
246
// so that such operation is safe.
242
- let paths = postorder ( item) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
247
+ let paths = preorder_rev ( item) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
243
248
for path in paths {
244
249
self . transform_path ( path) ;
245
250
}
246
251
247
- postorder ( item) . filter_map ( ast:: Lifetime :: cast) . for_each ( |lifetime| {
252
+ preorder_rev ( item) . filter_map ( ast:: Lifetime :: cast) . for_each ( |lifetime| {
248
253
if let Some ( subst) = self . lifetime_substs . get ( & lifetime. syntax ( ) . text ( ) . to_string ( ) ) {
249
254
ted:: replace ( lifetime. syntax ( ) , subst. clone_subtree ( ) . clone_for_update ( ) . syntax ( ) ) ;
250
255
}
@@ -263,7 +268,7 @@ impl Ctx<'_> {
263
268
// `transform_path` may update a node's parent and that would break the
264
269
// tree traversal. Thus all paths in the tree are collected into a vec
265
270
// so that such operation is safe.
266
- let paths = postorder ( value) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
271
+ let paths = preorder_rev ( value) . filter_map ( ast:: Path :: cast) . collect :: < Vec < _ > > ( ) ;
267
272
for path in paths {
268
273
self . transform_path ( path) ;
269
274
}
0 commit comments