This commit is contained in:
Aleksey Kladov 2019-12-22 19:31:01 +01:00
parent 78f7683b9a
commit 007032f850
2 changed files with 11 additions and 10 deletions

View File

@ -70,18 +70,20 @@ pub(crate) fn legacy_macros<'a>(&'a self) -> impl Iterator<Item = (&'a Name, Mac
}
/// Get a name from current module scope, legacy macros are not included
pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&PerNs> {
pub(crate) fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<PerNs> {
match shadow {
BuiltinShadowMode::Module => self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)),
BuiltinShadowMode::Module => {
self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)).copied()
}
BuiltinShadowMode::Other => {
let item = self.visible.get(name);
let item = self.visible.get(name).copied();
if let Some(def) = item {
if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
return BUILTIN_SCOPE.get(name).or(item);
return BUILTIN_SCOPE.get(name).copied().or(item);
}
}
item.or_else(|| BUILTIN_SCOPE.get(name))
item.or_else(|| BUILTIN_SCOPE.get(name).copied())
}
}
}

View File

@ -181,7 +181,7 @@ pub(super) fn resolve_path_fp_with_macro(
// Since it is a qualified path here, it should not contains legacy macros
match self[module.local_id].scope.get(&segment, prefer_module(i)) {
Some(def) => *def,
Some(def) => def,
_ => {
log::debug!("path segment {:?} not found", segment);
return ResolvePathResult::empty(ReachedFixedPoint::No);
@ -243,7 +243,7 @@ fn resolve_name_in_module(
// - std prelude
let from_legacy_macro =
self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros);
let from_scope = self[module].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none);
let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none);
let from_extern_prelude =
self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
let from_prelude = self.resolve_in_prelude(db, name, shadow);
@ -256,8 +256,7 @@ fn resolve_name_in_crate_root_or_extern_prelude(
name: &Name,
shadow: BuiltinShadowMode,
) -> PerNs {
let from_crate_root =
self[self.root].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none);
let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none);
let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
from_crate_root.or(from_extern_prelude)
@ -278,7 +277,7 @@ fn resolve_in_prelude(
keep = db.crate_def_map(prelude.krate);
&keep
};
def_map[prelude.local_id].scope.get(name, shadow).copied().unwrap_or_else(PerNs::none)
def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none)
} else {
PerNs::none()
}