mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +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),
|
ModuleId(ModuleId),
|
||||||
ImplId(ImplId),
|
ImplId(ImplId),
|
||||||
TraitId(TraitId),
|
TraitId(TraitId),
|
||||||
|
DefWithBodyId(DefWithBodyId),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A Data Type
|
/// A Data Type
|
||||||
|
@ -478,33 +479,32 @@ pub trait HasModule {
|
||||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
|
fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for FunctionLoc {
|
impl HasModule for ContainerId {
|
||||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||||
match self.container {
|
match *self {
|
||||||
ContainerId::ModuleId(it) => it,
|
ContainerId::ModuleId(it) => it,
|
||||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
ContainerId::ImplId(it) => it.lookup(db).container,
|
||||||
ContainerId::TraitId(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 {
|
impl HasModule for TypeAliasLoc {
|
||||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||||
match self.container {
|
self.container.module(db)
|
||||||
ContainerId::ModuleId(it) => it,
|
|
||||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
|
||||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HasModule for ConstLoc {
|
impl HasModule for ConstLoc {
|
||||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||||
match self.container {
|
self.container.module(db)
|
||||||
ContainerId::ModuleId(it) => it,
|
|
||||||
ContainerId::ImplId(it) => it.lookup(db).container,
|
|
||||||
ContainerId::TraitId(it) => it.lookup(db).container,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -586,6 +586,7 @@ impl HasResolver for ContainerId {
|
||||||
ContainerId::TraitId(it) => it.resolver(db),
|
ContainerId::TraitId(it) => it.resolver(db),
|
||||||
ContainerId::ImplId(it) => it.resolver(db),
|
ContainerId::ImplId(it) => it.resolver(db),
|
||||||
ContainerId::ModuleId(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)
|
Some(substs)
|
||||||
}
|
}
|
||||||
ContainerId::ModuleId(_) => None,
|
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
self.write_assoc_resolution(id, item.into());
|
self.write_assoc_resolution(id, item.into());
|
||||||
|
|
|
@ -6,8 +6,8 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use arrayvec::ArrayVec;
|
use arrayvec::ArrayVec;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, FunctionId,
|
lang_item::LangItemTarget, resolver::Resolver, type_ref::Mutability, AssocItemId, ContainerId,
|
||||||
HasModule, ImplId, Lookup, TraitId,
|
FunctionId, HasModule, ImplId, Lookup, TraitId,
|
||||||
};
|
};
|
||||||
use hir_expand::name::Name;
|
use hir_expand::name::Name;
|
||||||
use ra_db::CrateId;
|
use ra_db::CrateId;
|
||||||
|
@ -451,12 +451,12 @@ fn transform_receiver_ty(
|
||||||
self_ty: &Canonical<Ty>,
|
self_ty: &Canonical<Ty>,
|
||||||
) -> Option<Ty> {
|
) -> Option<Ty> {
|
||||||
let substs = match function_id.lookup(db).container {
|
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())
|
.push(self_ty.value.clone())
|
||||||
.fill_with_unknown()
|
.fill_with_unknown()
|
||||||
.build(),
|
.build(),
|
||||||
hir_def::ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
|
ContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
|
||||||
hir_def::ContainerId::ModuleId(_) => unreachable!(),
|
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => unreachable!(),
|
||||||
};
|
};
|
||||||
let sig = db.callable_item_signature(function_id.into());
|
let sig = db.callable_item_signature(function_id.into());
|
||||||
Some(sig.params()[0].clone().subst(&substs))
|
Some(sig.params()[0].clone().subst(&substs))
|
||||||
|
|
|
@ -157,6 +157,6 @@ fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option<Generi
|
||||||
match container {
|
match container {
|
||||||
ContainerId::ImplId(it) => Some(it.into()),
|
ContainerId::ImplId(it) => Some(it.into()),
|
||||||
ContainerId::TraitId(it) => Some(it.into()),
|
ContainerId::TraitId(it) => Some(it.into()),
|
||||||
ContainerId::ModuleId(_) => None,
|
ContainerId::ModuleId(_) | ContainerId::DefWithBodyId(_) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue