Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print visible name for types as well as modules. #57802

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/librustc/ty/item_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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(|| {
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/issues/auxiliary/issue-56943.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub struct S;
mod m { pub struct S; }
pub use crate::m::S as S2;
8 changes: 8 additions & 0 deletions src/test/ui/issues/issue-56943.rs
Original file line number Diff line number Diff line change
@@ -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]
}
12 changes: 12 additions & 0 deletions src/test/ui/issues/issue-56943.stderr
Original file line number Diff line number Diff line change
@@ -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`.