diff options
| author | David Wood <david@davidtw.co> | 2019-01-21 13:25:15 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2019-01-21 13:25:15 +0100 |
| commit | 1db42756f7fec98d3705a0f975a1c92d10e88cd7 (patch) | |
| tree | efd27ee196bca88c518f9294e6cfbd5e992168c8 /src/librustc/ty | |
| parent | b5f5a2715ed8685bc19fd589a23c7c658c2fe6bd (diff) | |
| download | rust-1db42756f7fec98d3705a0f975a1c92d10e88cd7.tar.gz rust-1db42756f7fec98d3705a0f975a1c92d10e88cd7.zip | |
Print visible name for types as well as modules.
This commit extends previous work in #55007 where the name from the visible parent was used for modules. Now, we also print the name from the visible parent for types.
Diffstat (limited to 'src/librustc/ty')
| -rw-r--r-- | src/librustc/ty/item_path.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/librustc/ty/item_path.rs b/src/librustc/ty/item_path.rs index 9328de4f6a0..0ddc5ae8720 100644 --- a/src/librustc/ty/item_path.rs +++ b/src/librustc/ty/item_path.rs @@ -210,12 +210,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { let visible_parent = visible_parent_map.get(&cur_def).cloned(); let actual_parent = self.parent(cur_def); - debug!( - "try_push_visible_item_path: visible_parent={:?} actual_parent={:?}", - visible_parent, actual_parent, - ); let data = cur_def_key.disambiguated_data.data; + debug!( + "try_push_visible_item_path: data={:?} visible_parent={:?} actual_parent={:?}", + data, visible_parent, actual_parent, + ); let symbol = match data { // In order to output a path that could actually be imported (valid and visible), // we need to handle re-exports correctly. @@ -248,16 +248,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { // the children of the visible parent (as was done when computing // `visible_parent_map`), looking for the specific child we currently have and then // have access to the re-exported name. - DefPathData::Module(module_name) if visible_parent != actual_parent => { - let mut name: Option<ast::Ident> = None; - if let Some(visible_parent) = visible_parent { - for child in self.item_children(visible_parent).iter() { - if child.def.def_id() == cur_def { - name = Some(child.ident); - } - } - } - name.map(|n| n.as_str()).unwrap_or(module_name.as_str()) + DefPathData::Module(actual_name) | + DefPathData::TypeNs(actual_name) if visible_parent != actual_parent => { + visible_parent + .and_then(|parent| { + self.item_children(parent) + .iter() + .find(|child| child.def.def_id() == cur_def) + .map(|child| child.ident.as_str()) + }) + .unwrap_or_else(|| actual_name.as_str()) }, _ => { data.get_opt_name().map(|n| n.as_str()).unwrap_or_else(|| { |
