Skip to content

Commit 49716e6

Browse files
committed
Auto merge of rust-lang#15472 - Veykril:import-ide-support, r=Veykril
internal: Record import origins in ItemScope and PerNS This records the import items definitions come from in the module scope (as well as what an import resolves to in an ItemScope). It does ignore glob imports as thats a lot more work for little to no gain, glob imports act as if the importing items are "inlined" into the scope which suffices for almost all use cases I believe (to my knowledge, attributes on them have little effect). There is still a lot of work needed to make this available to the IDE layer, but this lays out the ground work for havin IDE layer support. cc rust-lang/rust-analyzer#14079
2 parents e69b96b + a17d73a commit 49716e6

27 files changed

+730
-387
lines changed

crates/hir-def/src/body/tests/block.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ fn outer() {
3838
"#,
3939
expect![[r#"
4040
block scope
41-
CrateStruct: t
42-
PlainStruct: t v
43-
SelfStruct: t
41+
CrateStruct: ti
42+
PlainStruct: ti vi
43+
SelfStruct: ti
4444
Struct: v
4545
SuperStruct: _
4646
@@ -66,7 +66,7 @@ fn outer() {
6666
"#,
6767
expect![[r#"
6868
block scope
69-
imported: t v
69+
imported: ti vi
7070
name: v
7171
7272
crate
@@ -92,9 +92,9 @@ fn outer() {
9292
"#,
9393
expect![[r#"
9494
block scope
95-
inner1: t
95+
inner1: ti
9696
inner2: v
97-
outer: v
97+
outer: vi
9898
9999
block scope
100100
inner: v
@@ -121,7 +121,7 @@ struct Struct {}
121121
"#,
122122
expect![[r#"
123123
block scope
124-
Struct: t
124+
Struct: ti
125125
126126
crate
127127
Struct: t
@@ -153,7 +153,7 @@ fn outer() {
153153
"#,
154154
expect![[r#"
155155
block scope
156-
ResolveMe: t
156+
ResolveMe: ti
157157
158158
block scope
159159
m2: t
@@ -214,7 +214,7 @@ fn f() {
214214
"#,
215215
expect![[r#"
216216
block scope
217-
ResolveMe: t
217+
ResolveMe: ti
218218
219219
block scope
220220
h: v
@@ -292,7 +292,7 @@ pub mod cov_mark {
292292
nested: v
293293
294294
crate
295-
cov_mark: t
295+
cov_mark: ti
296296
f: v
297297
"#]],
298298
);

crates/hir-def/src/find_path.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,4 +1293,22 @@ pub mod prelude {
12931293
"None",
12941294
);
12951295
}
1296+
1297+
#[test]
1298+
fn different_crate_renamed_through_dep() {
1299+
check_found_path(
1300+
r#"
1301+
//- /main.rs crate:main deps:intermediate
1302+
$0
1303+
//- /intermediate.rs crate:intermediate deps:std
1304+
pub extern crate std as std_renamed;
1305+
//- /std.rs crate:std
1306+
pub struct S;
1307+
"#,
1308+
"intermediate::std_renamed::S",
1309+
"intermediate::std_renamed::S",
1310+
"intermediate::std_renamed::S",
1311+
"intermediate::std_renamed::S",
1312+
);
1313+
}
12961314
}

crates/hir-def/src/import_map.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,27 @@ fn collect_import_map(db: &dyn DefDatabase, krate: CrateId) -> FxIndexMap<ItemIn
114114

115115
for (name, per_ns) in visible_items {
116116
for item in per_ns.iter_items() {
117+
// FIXME: Not yet used, but will be once we handle doc(hidden) import sources
118+
let is_doc_hidden = false;
119+
117120
let import_info = ImportInfo {
118121
name: name.clone(),
119122
container: module,
120123
is_trait_assoc_item: false,
121124
};
122125

123126
match depth_map.entry(item) {
124-
Entry::Vacant(entry) => {
125-
entry.insert(depth);
126-
}
127+
Entry::Vacant(entry) => _ = entry.insert((depth, is_doc_hidden)),
127128
Entry::Occupied(mut entry) => {
128-
if depth < *entry.get() {
129-
entry.insert(depth);
130-
} else {
129+
let &(occ_depth, occ_is_doc_hidden) = entry.get();
130+
// Prefer the one that is not doc(hidden),
131+
// Otherwise, if both have the same doc(hidden)-ness and the new path is shorter, prefer that one.
132+
let overwrite_entry = occ_is_doc_hidden && !is_doc_hidden
133+
|| occ_is_doc_hidden == is_doc_hidden && depth < occ_depth;
134+
if !overwrite_entry {
131135
continue;
132136
}
137+
entry.insert((depth, is_doc_hidden));
133138
}
134139
}
135140

0 commit comments

Comments
 (0)