Skip to content

Commit 2e1d739

Browse files
committed
Import glob imports from other crates
This is the easy part since we don't have to consider the fixpoint algorithm.
1 parent c1e2956 commit 2e1d739

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

crates/ra_hir/src/marks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ test_utils::marks!(
55
type_var_cycles_resolve_as_possible
66
type_var_resolves_to_int_var
77
glob_enum
8+
glob_across_crates
89
);

crates/ra_hir/src/nameres.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,25 @@ where
276276
log::debug!("glob import: {:?}", import);
277277
match def.take_types() {
278278
Some(ModuleDef::Module(m)) => {
279-
// TODO
279+
if m.krate != self.krate {
280+
tested_by!(glob_across_crates);
281+
// glob import from other crate => we can just import everything once
282+
let item_map = self.db.item_map(m.krate);
283+
let scope = &item_map[m.module_id];
284+
self.update(module_id, |items| {
285+
// TODO: handle shadowing and visibility
286+
items.items.extend(
287+
scope.items.iter().map(|(name, res)| (name.clone(), res.clone())),
288+
);
289+
});
290+
}
280291
}
281292
Some(ModuleDef::Enum(e)) => {
282293
tested_by!(glob_enum);
294+
// glob import from enum => just import all the variants
283295
let variants = e.variants(self.db);
284-
let resolutions = variants.into_iter()
296+
let resolutions = variants
297+
.into_iter()
285298
.filter_map(|variant| {
286299
let res = Resolution {
287300
def: PerNs::both(variant.into(), e.into()),

crates/ra_hir/src/nameres/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ fn glob_enum() {
251251

252252
#[test]
253253
fn glob_across_crates() {
254+
covers!(glob_across_crates);
254255
let (mut db, sr) = MockDatabase::with_files(
255256
"
256257
//- /main.rs

0 commit comments

Comments
 (0)