mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Impl HasAttrs for GenericParam
This commit is contained in:
parent
b4a7caedb0
commit
ec448ca4b3
5 changed files with 78 additions and 11 deletions
|
@ -21,7 +21,7 @@ use crate::{
|
|||
nameres::ModuleSource,
|
||||
path::{ModPath, PathKind},
|
||||
src::HasChildSource,
|
||||
AdtId, AttrDefId, Lookup,
|
||||
AdtId, AttrDefId, GenericParamId, Lookup,
|
||||
};
|
||||
|
||||
/// Holds documentation
|
||||
|
@ -235,6 +235,25 @@ impl Attrs {
|
|||
AttrDefId::StaticId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||
AttrDefId::FunctionId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||
AttrDefId::TypeAliasId(it) => attrs_from_item_tree(it.lookup(db).id, db),
|
||||
AttrDefId::GenericParamId(it) => match it {
|
||||
GenericParamId::TypeParamId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
RawAttrs::from_attrs_owner(
|
||||
db,
|
||||
src.with_value(
|
||||
src.value[it.local_id].as_ref().either(|it| it as _, |it| it as _),
|
||||
),
|
||||
)
|
||||
}
|
||||
GenericParamId::LifetimeParamId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
RawAttrs::from_attrs_owner(db, src.with_value(&src.value[it.local_id]))
|
||||
}
|
||||
GenericParamId::ConstParamId(it) => {
|
||||
let src = it.parent.child_source(db);
|
||||
RawAttrs::from_attrs_owner(db, src.with_value(&src.value[it.local_id]))
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
raw_attrs.filter(db, def.krate(db))
|
||||
|
|
|
@ -261,6 +261,15 @@ pub enum AdtId {
|
|||
}
|
||||
impl_from!(StructId, UnionId, EnumId for AdtId);
|
||||
|
||||
/// A generic param
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum GenericParamId {
|
||||
TypeParamId(TypeParamId),
|
||||
LifetimeParamId(LifetimeParamId),
|
||||
ConstParamId(ConstParamId),
|
||||
}
|
||||
impl_from!(TypeParamId, LifetimeParamId, ConstParamId for GenericParamId);
|
||||
|
||||
/// The defs which can be visible in the module.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum ModuleDefId {
|
||||
|
@ -357,6 +366,7 @@ pub enum AttrDefId {
|
|||
TypeAliasId(TypeAliasId),
|
||||
MacroDefId(MacroDefId),
|
||||
ImplId(ImplId),
|
||||
GenericParamId(GenericParamId),
|
||||
}
|
||||
|
||||
impl_from!(
|
||||
|
@ -370,7 +380,8 @@ impl_from!(
|
|||
TraitId,
|
||||
TypeAliasId,
|
||||
MacroDefId,
|
||||
ImplId
|
||||
ImplId,
|
||||
GenericParamId
|
||||
for AttrDefId
|
||||
);
|
||||
|
||||
|
@ -495,6 +506,15 @@ impl AttrDefId {
|
|||
AttrDefId::TraitId(it) => it.lookup(db).container.module(db).krate,
|
||||
AttrDefId::TypeAliasId(it) => it.lookup(db).module(db).krate,
|
||||
AttrDefId::ImplId(it) => it.lookup(db).container.module(db).krate,
|
||||
AttrDefId::GenericParamId(it) => {
|
||||
match it {
|
||||
GenericParamId::TypeParamId(it) => it.parent,
|
||||
GenericParamId::LifetimeParamId(it) => it.parent,
|
||||
GenericParamId::ConstParamId(it) => it.parent,
|
||||
}
|
||||
.module(db)
|
||||
.krate
|
||||
}
|
||||
// FIXME: `MacroDefId` should store the defining module, then this can implement
|
||||
// `HasModule`
|
||||
AttrDefId::MacroDefId(it) => it.krate,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue