diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs index 5732eeccf1e..50d4e824cd7 100644 --- a/crates/ra_hir/src/marks.rs +++ b/crates/ra_hir/src/marks.rs @@ -5,4 +5,5 @@ test_utils::marks!( type_var_cycles_resolve_as_possible type_var_resolves_to_int_var glob_enum + glob_across_crates ); diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 0b6ab12110c..2442e754e5a 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -276,12 +276,25 @@ where log::debug!("glob import: {:?}", import); match def.take_types() { Some(ModuleDef::Module(m)) => { - // TODO + if m.krate != self.krate { + tested_by!(glob_across_crates); + // glob import from other crate => we can just import everything once + let item_map = self.db.item_map(m.krate); + let scope = &item_map[m.module_id]; + self.update(module_id, |items| { + // TODO: handle shadowing and visibility + items.items.extend( + scope.items.iter().map(|(name, res)| (name.clone(), res.clone())), + ); + }); + } } Some(ModuleDef::Enum(e)) => { tested_by!(glob_enum); + // glob import from enum => just import all the variants let variants = e.variants(self.db); - let resolutions = variants.into_iter() + let resolutions = variants + .into_iter() .filter_map(|variant| { let res = Resolution { def: PerNs::both(variant.into(), e.into()), diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 91566fc9849..9c0e4ef2936 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -251,6 +251,7 @@ fn glob_enum() { #[test] fn glob_across_crates() { + covers!(glob_across_crates); let (mut db, sr) = MockDatabase::with_files( " //- /main.rs