mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Add body as a possible container for items
This commit is contained in:
parent
5bd8de3f5e
commit
ba12e83c26
5 changed files with 20 additions and 19 deletions
|
@ -335,6 +335,7 @@ pub enum ContainerId {
|
|||
ModuleId(ModuleId),
|
||||
ImplId(ImplId),
|
||||
TraitId(TraitId),
|
||||
DefWithBodyId(DefWithBodyId),
|
||||
}
|
||||
|
||||
/// A Data Type
|
||||
|
@ -478,33 +479,32 @@ pub trait HasModule {
|
|||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
|
||||
}
|
||||
|
||||
impl HasModule for FunctionLoc {
|
||||
impl HasModule for ContainerId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
match *self {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
ContainerId::DefWithBodyId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for FunctionLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
self.container.module(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for TypeAliasLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
}
|
||||
self.container.module(db)
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for ConstLoc {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match self.container {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
||||
}
|
||||
self.container.module(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -586,6 +586,7 @@ impl HasResolver for ContainerId {
|
|||
ContainerId::TraitId(it) => it.resolver(db),
|
||||
ContainerId::ImplId(it) => it.resolver(db),
|
||||
ContainerId::ModuleId(it) => it.resolver(db),
|
||||
ContainerId::DefWithBodyId(it) => it.resolver(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}));
|
||||
Some(substs)
|
||||
}
|
||||
ContainerId::ModuleId(_) => None,
|
||||
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
|
||||
};
|
||||
|
||||
self.write_assoc_resolution(id, item.into());
|
||||
|
|
|
@ -6,8 +6,8 @@ use std::sync::Arc;
|
|||
|
||||
use arrayvec::ArrayVec;
|
||||
use hir_def::{
|
||||
lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, FunctionId,
|
||||
HasModule, ImplId, Lookup, TraitId,
|
||||
lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, ContainerId,
|
||||
FunctionId, HasModule, ImplId, Lookup, TraitId,
|
||||
};
|
||||
use hir_expand::name::Name;
|
||||
use ra_db::CrateId;
|
||||
|
@ -451,12 +451,12 @@ fn transform_receiver_ty(
|
|||
self_ty: &Canonical<Ty>,
|
||||
) -> Option<Ty> {
|
||||
let substs = match function_id.lookup(db).container {
|
||||
hir_def::ContainerId::TraitId(_) => Substs::build_for_def(db, function_id)
|
||||
ContainerId::TraitId(_) => Substs::build_for_def(db, function_id)
|
||||
.push(self_ty.value.clone())
|
||||
.fill_with_unknown()
|
||||
.build(),
|
||||
hir_def::ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
|
||||
hir_def::ContainerId::ModuleId(_) => unreachable!(),
|
||||
ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
|
||||
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => unreachable!(),
|
||||
};
|
||||
let sig = db.callable_item_signature(function_id.into());
|
||||
Some(sig.params()[0].clone().subst(&substs))
|
||||
|
|
|
@ -157,6 +157,6 @@ fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<Generi
|
|||
match container {
|
||||
ContainerId::ImplId(it) => Some(it.into()),
|
||||
ContainerId::TraitId(it) => Some(it.into()),
|
||||
ContainerId::ModuleId(_) => None,
|
||||
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue