Import glob imports from other crates

This is the easy part since we don't have to consider the fixpoint algorithm.
This commit is contained in:
Florian Diebold 2019-02-10 15:41:44 +01:00
parent c1e295682e
commit 2e1d739a80
3 changed files with 17 additions and 2 deletions

View File

@ -5,4 +5,5 @@ test_utils::marks!(
type_var_cycles_resolve_as_possible
type_var_resolves_to_int_var
glob_enum
glob_across_crates
);

View File

@ -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()),

View File

@ -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