mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-13 08:27:17 +00:00
Introduce ContainerId
This commit is contained in:
parent
8fc20b6503
commit
94ad07af4b
7 changed files with 42 additions and 19 deletions
|
@ -25,7 +25,7 @@ use crate::{
|
|||
path::GenericArgs,
|
||||
path::Path,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AssocContainerId, DefWithBodyId, FunctionLoc, Intern,
|
||||
ContainerId, DefWithBodyId, FunctionLoc, Intern,
|
||||
};
|
||||
|
||||
pub(super) fn lower(
|
||||
|
@ -490,7 +490,7 @@ where
|
|||
}
|
||||
|
||||
fn collect_block_items(&mut self, block: &ast::Block) {
|
||||
let container = AssocContainerId::DefWithBodyId(self.def);
|
||||
let container = ContainerId::DefWithBodyId(self.def).into();
|
||||
for item in block.items() {
|
||||
match item {
|
||||
ast::ModuleItem::FnDef(def) => {
|
||||
|
|
|
@ -331,13 +331,19 @@ pub struct LocalTypeParamId(RawId);
|
|||
impl_arena_id!(LocalTypeParamId);
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum AssocContainerId {
|
||||
pub enum ContainerId {
|
||||
ModuleId(ModuleId),
|
||||
ImplId(ImplId),
|
||||
TraitId(TraitId),
|
||||
DefWithBodyId(DefWithBodyId),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum AssocContainerId {
|
||||
ContainerId(ContainerId),
|
||||
ImplId(ImplId),
|
||||
TraitId(TraitId),
|
||||
}
|
||||
impl_froms!(AssocContainerId: ContainerId);
|
||||
|
||||
/// A Data Type
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum AdtId {
|
||||
|
@ -479,13 +485,21 @@ pub trait HasModule {
|
|||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId;
|
||||
}
|
||||
|
||||
impl HasModule for ContainerId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match *self {
|
||||
ContainerId::ModuleId(it) => it,
|
||||
ContainerId::DefWithBodyId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasModule for AssocContainerId {
|
||||
fn module(&self, db: &impl db::DefDatabase) -> ModuleId {
|
||||
match *self {
|
||||
AssocContainerId::ModuleId(it) => it,
|
||||
AssocContainerId::ContainerId(it) => it.module(db),
|
||||
AssocContainerId::ImplId(it) => it.lookup(db).container,
|
||||
AssocContainerId::TraitId(it) => it.lookup(db).container,
|
||||
AssocContainerId::DefWithBodyId(it) => it.module(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ use crate::{
|
|||
},
|
||||
path::{ModPath, PathKind},
|
||||
per_ns::PerNs,
|
||||
AdtId, AssocContainerId, AstId, ConstLoc, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
|
||||
AdtId, AstId, ConstLoc, ContainerId, EnumLoc, EnumVariantId, FunctionLoc, ImplLoc, Intern,
|
||||
LocalImportId, LocalModuleId, ModuleDefId, ModuleId, StaticLoc, StructLoc, TraitLoc,
|
||||
TypeAliasLoc, UnionLoc,
|
||||
};
|
||||
|
@ -760,10 +760,11 @@ where
|
|||
self.collect_derives(attrs, def);
|
||||
|
||||
let name = def.name.clone();
|
||||
let container = ContainerId::ModuleId(module);
|
||||
let def: PerNs = match def.kind {
|
||||
raw::DefKind::Function(ast_id) => {
|
||||
let def = FunctionLoc {
|
||||
container: AssocContainerId::ModuleId(module),
|
||||
container: container.into(),
|
||||
ast_id: AstId::new(self.file_id, ast_id),
|
||||
}
|
||||
.intern(self.def_collector.db);
|
||||
|
@ -787,7 +788,7 @@ where
|
|||
}
|
||||
raw::DefKind::Const(ast_id) => {
|
||||
let def = ConstLoc {
|
||||
container: AssocContainerId::ModuleId(module),
|
||||
container: container.into(),
|
||||
ast_id: AstId::new(self.file_id, ast_id),
|
||||
}
|
||||
.intern(self.def_collector.db);
|
||||
|
@ -808,7 +809,7 @@ where
|
|||
}
|
||||
raw::DefKind::TypeAlias(ast_id) => {
|
||||
let def = TypeAliasLoc {
|
||||
container: AssocContainerId::ModuleId(module),
|
||||
container: container.into(),
|
||||
ast_id: AstId::new(self.file_id, ast_id),
|
||||
}
|
||||
.intern(self.def_collector.db);
|
||||
|
|
|
@ -17,9 +17,9 @@ use crate::{
|
|||
nameres::{BuiltinShadowMode, CrateDefMap},
|
||||
path::{ModPath, PathKind},
|
||||
per_ns::PerNs,
|
||||
AdtId, AssocContainerId, ConstId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
|
||||
GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, StaticId,
|
||||
StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
|
||||
AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId,
|
||||
FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId,
|
||||
StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -580,13 +580,21 @@ impl HasResolver for DefWithBodyId {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasResolver for ContainerId {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
match self {
|
||||
ContainerId::ModuleId(it) => it.resolver(db),
|
||||
ContainerId::DefWithBodyId(it) => it.resolver(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasResolver for AssocContainerId {
|
||||
fn resolver(self, db: &impl DefDatabase) -> Resolver {
|
||||
match self {
|
||||
AssocContainerId::ContainerId(it) => it.resolver(db),
|
||||
AssocContainerId::TraitId(it) => it.resolver(db),
|
||||
AssocContainerId::ImplId(it) => it.resolver(db),
|
||||
AssocContainerId::ModuleId(it) => it.resolver(db),
|
||||
AssocContainerId::DefWithBodyId(it) => it.resolver(db),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -237,7 +237,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
|
|||
}));
|
||||
Some(substs)
|
||||
}
|
||||
AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => None,
|
||||
AssocContainerId::ContainerId(_) => None,
|
||||
};
|
||||
|
||||
self.write_assoc_resolution(id, item.into());
|
||||
|
|
|
@ -456,7 +456,7 @@ fn transform_receiver_ty(
|
|||
.fill_with_unknown()
|
||||
.build(),
|
||||
AssocContainerId::ImplId(impl_id) => inherent_impl_substs(db, impl_id, &self_ty)?,
|
||||
AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => unreachable!(),
|
||||
AssocContainerId::ContainerId(_) => 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 {
|
||||
AssocContainerId::ImplId(it) => Some(it.into()),
|
||||
AssocContainerId::TraitId(it) => Some(it.into()),
|
||||
AssocContainerId::ModuleId(_) | AssocContainerId::DefWithBodyId(_) => None,
|
||||
AssocContainerId::ContainerId(_) => None,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue