mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Move ScopeDef
This commit is contained in:
parent
061e6c77b5
commit
1312c57d34
4 changed files with 31 additions and 31 deletions
|
@ -10,6 +10,7 @@ use hir_def::{
|
|||
adt::VariantData,
|
||||
body::scope::ExprScopes,
|
||||
builtin_type::BuiltinType,
|
||||
nameres::per_ns::PerNs,
|
||||
traits::TraitData,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
ContainerId, CrateModuleId, HasModule, ImplId, LocalEnumVariantId, LocalStructFieldId, Lookup,
|
||||
|
@ -32,7 +33,7 @@ use crate::{
|
|||
},
|
||||
resolve::{HasResolver, TypeNs},
|
||||
ty::{InferenceResult, Namespace, TraitRef},
|
||||
Either, HasSource, ImportId, Name, ScopeDef, Source, Ty,
|
||||
Either, HasSource, ImportId, Name, Source, Ty,
|
||||
};
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
|
@ -1064,3 +1065,26 @@ pub struct GenericParam {
|
|||
pub struct ImplBlock {
|
||||
pub(crate) id: ImplId,
|
||||
}
|
||||
|
||||
/// For IDE only
|
||||
pub enum ScopeDef {
|
||||
ModuleDef(ModuleDef),
|
||||
MacroDef(MacroDef),
|
||||
GenericParam(u32),
|
||||
ImplSelfType(ImplBlock),
|
||||
AdtSelfType(Adt),
|
||||
Local(Local),
|
||||
Unknown,
|
||||
}
|
||||
|
||||
impl From<PerNs> for ScopeDef {
|
||||
fn from(def: PerNs) -> Self {
|
||||
def.take_types()
|
||||
.or_else(|| def.take_values())
|
||||
.map(|module_def_id| ScopeDef::ModuleDef(module_def_id.into()))
|
||||
.or_else(|| {
|
||||
def.get_macros().map(|macro_def_id| ScopeDef::MacroDef(macro_def_id.into()))
|
||||
})
|
||||
.unwrap_or(ScopeDef::Unknown)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue