mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
Simplify
This commit is contained in:
parent
007032f850
commit
7c405c0156
2 changed files with 17 additions and 16 deletions
|
@ -70,20 +70,27 @@ impl ItemScope {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a name from current module scope, legacy macros are not included
|
/// 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) -> PerNs {
|
||||||
match shadow {
|
match shadow {
|
||||||
BuiltinShadowMode::Module => {
|
BuiltinShadowMode::Module => self
|
||||||
self.visible.get(name).or_else(|| BUILTIN_SCOPE.get(name)).copied()
|
.visible
|
||||||
}
|
.get(name)
|
||||||
|
.or_else(|| BUILTIN_SCOPE.get(name))
|
||||||
|
.copied()
|
||||||
|
.unwrap_or_else(PerNs::none),
|
||||||
BuiltinShadowMode::Other => {
|
BuiltinShadowMode::Other => {
|
||||||
let item = self.visible.get(name).copied();
|
let item = self.visible.get(name).copied();
|
||||||
if let Some(def) = item {
|
if let Some(def) = item {
|
||||||
if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
|
if let Some(ModuleDefId::ModuleId(_)) = def.take_types() {
|
||||||
return BUILTIN_SCOPE.get(name).copied().or(item);
|
return BUILTIN_SCOPE
|
||||||
|
.get(name)
|
||||||
|
.copied()
|
||||||
|
.or(item)
|
||||||
|
.unwrap_or_else(PerNs::none);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
item.or_else(|| BUILTIN_SCOPE.get(name).copied())
|
item.or_else(|| BUILTIN_SCOPE.get(name).copied()).unwrap_or_else(PerNs::none)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,13 +180,7 @@ impl CrateDefMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Since it is a qualified path here, it should not contains legacy macros
|
// Since it is a qualified path here, it should not contains legacy macros
|
||||||
match self[module.local_id].scope.get(&segment, prefer_module(i)) {
|
self[module.local_id].scope.get(&segment, prefer_module(i))
|
||||||
Some(def) => def,
|
|
||||||
_ => {
|
|
||||||
log::debug!("path segment {:?} not found", segment);
|
|
||||||
return ResolvePathResult::empty(ReachedFixedPoint::No);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
|
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
|
||||||
// enum variant
|
// enum variant
|
||||||
|
@ -243,7 +237,7 @@ impl CrateDefMap {
|
||||||
// - std prelude
|
// - std prelude
|
||||||
let from_legacy_macro =
|
let from_legacy_macro =
|
||||||
self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros);
|
self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros);
|
||||||
let from_scope = self[module].scope.get(name, shadow).unwrap_or_else(PerNs::none);
|
let from_scope = self[module].scope.get(name, shadow);
|
||||||
let from_extern_prelude =
|
let from_extern_prelude =
|
||||||
self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
|
self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
|
||||||
let from_prelude = self.resolve_in_prelude(db, name, shadow);
|
let from_prelude = self.resolve_in_prelude(db, name, shadow);
|
||||||
|
@ -256,7 +250,7 @@ impl CrateDefMap {
|
||||||
name: &Name,
|
name: &Name,
|
||||||
shadow: BuiltinShadowMode,
|
shadow: BuiltinShadowMode,
|
||||||
) -> PerNs {
|
) -> PerNs {
|
||||||
let from_crate_root = self[self.root].scope.get(name, shadow).unwrap_or_else(PerNs::none);
|
let from_crate_root = self[self.root].scope.get(name, shadow);
|
||||||
let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
|
let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
|
||||||
|
|
||||||
from_crate_root.or(from_extern_prelude)
|
from_crate_root.or(from_extern_prelude)
|
||||||
|
@ -277,7 +271,7 @@ impl CrateDefMap {
|
||||||
keep = db.crate_def_map(prelude.krate);
|
keep = db.crate_def_map(prelude.krate);
|
||||||
&keep
|
&keep
|
||||||
};
|
};
|
||||||
def_map[prelude.local_id].scope.get(name, shadow).unwrap_or_else(PerNs::none)
|
def_map[prelude.local_id].scope.get(name, shadow)
|
||||||
} else {
|
} else {
|
||||||
PerNs::none()
|
PerNs::none()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue