Skip to content

Commit 1db4275

Browse files
committed
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.
1 parent b5f5a27 commit 1db4275

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/librustc/ty/item_path.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
210210

211211
let visible_parent = visible_parent_map.get(&cur_def).cloned();
212212
let actual_parent = self.parent(cur_def);
213-
debug!(
214-
"try_push_visible_item_path: visible_parent={:?} actual_parent={:?}",
215-
visible_parent, actual_parent,
216-
);
217213

218214
let data = cur_def_key.disambiguated_data.data;
215+
debug!(
216+
"try_push_visible_item_path: data={:?} visible_parent={:?} actual_parent={:?}",
217+
data, visible_parent, actual_parent,
218+
);
219219
let symbol = match data {
220220
// In order to output a path that could actually be imported (valid and visible),
221221
// we need to handle re-exports correctly.
@@ -248,16 +248,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
248248
// the children of the visible parent (as was done when computing
249249
// `visible_parent_map`), looking for the specific child we currently have and then
250250
// have access to the re-exported name.
251-
DefPathData::Module(module_name) if visible_parent != actual_parent => {
252-
let mut name: Option<ast::Ident> = None;
253-
if let Some(visible_parent) = visible_parent {
254-
for child in self.item_children(visible_parent).iter() {
255-
if child.def.def_id() == cur_def {
256-
name = Some(child.ident);
257-
}
258-
}
259-
}
260-
name.map(|n| n.as_str()).unwrap_or(module_name.as_str())
251+
DefPathData::Module(actual_name) |
252+
DefPathData::TypeNs(actual_name) if visible_parent != actual_parent => {
253+
visible_parent
254+
.and_then(|parent| {
255+
self.item_children(parent)
256+
.iter()
257+
.find(|child| child.def.def_id() == cur_def)
258+
.map(|child| child.ident.as_str())
259+
})
260+
.unwrap_or_else(|| actual_name.as_str())
261261
},
262262
_ => {
263263
data.get_opt_name().map(|n| n.as_str()).unwrap_or_else(|| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub struct S;
2+
mod m { pub struct S; }
3+
pub use crate::m::S as S2;

src/test/ui/issues/issue-56943.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// aux-build:issue-56943.rs
2+
3+
extern crate issue_56943;
4+
5+
fn main() {
6+
let _: issue_56943::S = issue_56943::S2;
7+
//~^ ERROR mismatched types [E0308]
8+
}

src/test/ui/issues/issue-56943.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-56943.rs:6:29
3+
|
4+
LL | let _: issue_56943::S = issue_56943::S2;
5+
| ^^^^^^^^^^^^^^^ expected struct `issue_56943::S`, found struct `issue_56943::S2`
6+
|
7+
= note: expected type `issue_56943::S`
8+
found type `issue_56943::S2`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)