mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +00:00
Add ConstParams to the HIR
This commit is contained in:
parent
77ad203a71
commit
0acdb73076
16 changed files with 173 additions and 37 deletions
|
@ -18,10 +18,10 @@ use hir_def::{
|
|||
resolver::{HasResolver, Resolver},
|
||||
src::HasSource as _,
|
||||
type_ref::{Mutability, TypeRef},
|
||||
AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, DefWithBodyId, EnumId,
|
||||
FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId, LocalEnumVariantId, LocalFieldId,
|
||||
LocalModuleId, Lookup, ModuleId, StaticId, StructId, TraitId, TypeAliasId, TypeParamId,
|
||||
UnionId,
|
||||
AdtId, AssocContainerId, AssocItemId, AssocItemLoc, AttrDefId, ConstId, ConstParamId,
|
||||
DefWithBodyId, EnumId, FunctionId, GenericDefId, HasModule, ImplId, LifetimeParamId,
|
||||
LocalEnumVariantId, LocalFieldId, LocalModuleId, Lookup, ModuleId, StaticId, StructId, TraitId,
|
||||
TypeAliasId, TypeParamId, UnionId,
|
||||
};
|
||||
use hir_def::{find_path::PrefixKind, item_scope::ItemInNs, visibility::Visibility};
|
||||
use hir_expand::{
|
||||
|
@ -1125,7 +1125,12 @@ impl GenericDef {
|
|||
id: LifetimeParamId { parent: self.into(), local_id },
|
||||
})
|
||||
.map(GenericParam::LifetimeParam);
|
||||
ty_params.chain(lt_params).collect()
|
||||
let const_params = generics
|
||||
.consts
|
||||
.iter()
|
||||
.map(|(local_id, _)| ConstParam { id: ConstParamId { parent: self.into(), local_id } })
|
||||
.map(GenericParam::ConstParam);
|
||||
ty_params.chain(lt_params).chain(const_params).collect()
|
||||
}
|
||||
|
||||
pub fn type_params(self, db: &dyn HirDatabase) -> Vec<TypeParam> {
|
||||
|
@ -1237,8 +1242,9 @@ impl Label {
|
|||
pub enum GenericParam {
|
||||
TypeParam(TypeParam),
|
||||
LifetimeParam(LifetimeParam),
|
||||
ConstParam(ConstParam),
|
||||
}
|
||||
impl_from!(TypeParam, LifetimeParam for GenericParam);
|
||||
impl_from!(TypeParam, LifetimeParam, ConstParam for GenericParam);
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct TypeParam {
|
||||
|
@ -1300,6 +1306,26 @@ impl LifetimeParam {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ConstParam {
|
||||
pub(crate) id: ConstParamId,
|
||||
}
|
||||
|
||||
impl ConstParam {
|
||||
pub fn name(self, db: &dyn HirDatabase) -> Name {
|
||||
let params = db.generic_params(self.id.parent);
|
||||
params.consts[self.id.local_id].name.clone()
|
||||
}
|
||||
|
||||
pub fn module(self, db: &dyn HirDatabase) -> Module {
|
||||
self.id.parent.module(db.upcast()).into()
|
||||
}
|
||||
|
||||
pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef {
|
||||
self.id.parent.into()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Impl {
|
||||
pub(crate) id: ImplId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue