about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-01-25 01:37:02 +0100
committerGitHub <noreply@github.com>2019-01-25 01:37:02 +0100
commita9950f6a459b88ea7424724849f79ce3720e94e4 (patch)
treec2eb8d7c75d4b6ad8c2578222fd7deed7347d709 /src
parent2876801d188e11ec8c39b40d60ee4ded31c77d7f (diff)
parent1db42756f7fec98d3705a0f975a1c92d10e88cd7 (diff)
downloadrust-a9950f6a459b88ea7424724849f79ce3720e94e4.tar.gz
rust-a9950f6a459b88ea7424724849f79ce3720e94e4.zip
Rollup merge of #57802 - davidtwco:issue-56943, r=estebank
Print visible name for types as well as modules.

Fixes #56943 and fixes #57713.

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.

r? @estebank
Diffstat (limited to 'src')
-rw-r--r--src/librustc/ty/item_path.rs28
-rw-r--r--src/test/ui/issues/auxiliary/issue-56943.rs3
-rw-r--r--src/test/ui/issues/issue-56943.rs8
-rw-r--r--src/test/ui/issues/issue-56943.stderr12
4 files changed, 37 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(|| {
diff --git a/src/test/ui/issues/auxiliary/issue-56943.rs b/src/test/ui/issues/auxiliary/issue-56943.rs
new file mode 100644
index 00000000000..65b9beb91f9
--- /dev/null
+++ b/src/test/ui/issues/auxiliary/issue-56943.rs
@@ -0,0 +1,3 @@
+pub struct S;
+mod m { pub struct S; }
+pub use crate::m::S as S2;
diff --git a/src/test/ui/issues/issue-56943.rs b/src/test/ui/issues/issue-56943.rs
new file mode 100644
index 00000000000..8fc77abdbf5
--- /dev/null
+++ b/src/test/ui/issues/issue-56943.rs
@@ -0,0 +1,8 @@
+// aux-build:issue-56943.rs
+
+extern crate issue_56943;
+
+fn main() {
+    let _: issue_56943::S = issue_56943::S2;
+    //~^ ERROR mismatched types [E0308]
+}
diff --git a/src/test/ui/issues/issue-56943.stderr b/src/test/ui/issues/issue-56943.stderr
new file mode 100644
index 00000000000..27202051524
--- /dev/null
+++ b/src/test/ui/issues/issue-56943.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/issue-56943.rs:6:29
+   |
+LL |     let _: issue_56943::S = issue_56943::S2;
+   |                             ^^^^^^^^^^^^^^^ expected struct `issue_56943::S`, found struct `issue_56943::S2`
+   |
+   = note: expected type `issue_56943::S`
+              found type `issue_56943::S2`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.