@@ -1231,13 +1231,26 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12311231 }
12321232 }
12331233
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.
12341242 fn process_use_tree ( & mut self ,
12351243 use_tree : & ' l ast:: UseTree ,
12361244 id : NodeId ,
1237- parent_item : & ' l ast:: Item ,
1245+ root_item : & ' l ast:: Item ,
12381246 prefix : & ast:: Path ) {
12391247 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) ;
12411254
12421255 match use_tree. kind {
12431256 ast:: UseTreeKind :: Simple ( ident) => {
@@ -1276,6 +1289,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
12761289 span,
12771290 name : ident. to_string ( ) ,
12781291 value : String :: new ( ) ,
1292+ parent,
12791293 } ) ;
12801294 }
12811295 self . write_sub_paths_truncated ( & path) ;
@@ -1311,6 +1325,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
13111325 span,
13121326 name : "*" . to_owned ( ) ,
13131327 value : names. join ( ", " ) ,
1328+ parent,
13141329 } ) ;
13151330 }
13161331 self . write_sub_paths ( & path) ;
@@ -1325,7 +1340,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
13251340 span : path. span ,
13261341 } ;
13271342 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) ;
13291344 }
13301345 }
13311346 }
@@ -1389,6 +1404,9 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
13891404 if !self . span . filter_generated ( alias_span, item. span ) {
13901405 let span =
13911406 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) ;
13921410 self . dumper . import (
13931411 & Access {
13941412 public : false ,
@@ -1400,6 +1418,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc
14001418 span,
14011419 name : item. ident . to_string ( ) ,
14021420 value : String :: new ( ) ,
1421+ parent,
14031422 } ,
14041423 ) ;
14051424 }
0 commit comments