@@ -1231,13 +1231,26 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1231
1231
}
1232
1232
}
1233
1233
1234
+ /// Dumps imports in a use tree recursively.
1235
+ ///
1236
+ /// A use tree is an import that may contain nested braces (RFC 2128). The `use_tree` parameter
1237
+ /// is the current use tree under scrutiny, while `id` and `prefix` are its corresponding node
1238
+ /// id and path. `root_item` is the topmost use tree in the hierarchy.
1239
+ ///
1240
+ /// If `use_tree` is a simple or glob import, it is dumped into the analysis data. Otherwise,
1241
+ /// each child use tree is dumped recursively.
1234
1242
fn process_use_tree ( & mut self ,
1235
1243
use_tree : & ' l ast:: UseTree ,
1236
1244
id : NodeId ,
1237
- parent_item : & ' l ast:: Item ,
1245
+ root_item : & ' l ast:: Item ,
1238
1246
prefix : & ast:: Path ) {
1239
1247
let path = & use_tree. prefix ;
1240
- let access = access_from ! ( self . save_ctxt, parent_item) ;
1248
+ let access = access_from ! ( self . save_ctxt, root_item) ;
1249
+
1250
+ // The parent def id of a given use tree is always the enclosing item.
1251
+ let parent = self . save_ctxt . tcx . hir . opt_local_def_id ( id)
1252
+ . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1253
+ . map ( :: id_from_def_id) ;
1241
1254
1242
1255
match use_tree. kind {
1243
1256
ast:: UseTreeKind :: Simple ( ident) => {
@@ -1276,6 +1289,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1276
1289
span,
1277
1290
name : ident. to_string ( ) ,
1278
1291
value : String :: new ( ) ,
1292
+ parent,
1279
1293
} ) ;
1280
1294
}
1281
1295
self . write_sub_paths_truncated ( & path) ;
@@ -1311,6 +1325,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1311
1325
span,
1312
1326
name : "*" . to_owned ( ) ,
1313
1327
value : names. join ( ", " ) ,
1328
+ parent,
1314
1329
} ) ;
1315
1330
}
1316
1331
self . write_sub_paths ( & path) ;
@@ -1325,7 +1340,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
1325
1340
span : path. span ,
1326
1341
} ;
1327
1342
for & ( ref tree, id) in nested_items {
1328
- self . process_use_tree ( tree, id, parent_item , & prefix) ;
1343
+ self . process_use_tree ( tree, id, root_item , & prefix) ;
1329
1344
}
1330
1345
}
1331
1346
}
@@ -1389,6 +1404,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1389
1404
if !self . span . filter_generated ( alias_span, item. span ) {
1390
1405
let span =
1391
1406
self . span_from_span ( alias_span. expect ( "No span found for extern crate" ) ) ;
1407
+ let parent = self . save_ctxt . tcx . hir . opt_local_def_id ( item. id )
1408
+ . and_then ( |id| self . save_ctxt . tcx . parent_def_id ( id) )
1409
+ . map ( :: id_from_def_id) ;
1392
1410
self . dumper . import (
1393
1411
& Access {
1394
1412
public : false ,
@@ -1400,6 +1418,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
1400
1418
span,
1401
1419
name : item. ident . to_string ( ) ,
1402
1420
value : String :: new ( ) ,
1421
+ parent,
1403
1422
} ,
1404
1423
) ;
1405
1424
}
0 commit comments