From 68336fdb61e080e1bfb008fd7742ee22ccc51829 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 2 Jan 2021 12:11:46 +0100 Subject: Implement HasAttrs for Type-, Const- and LifetimeParam --- crates/hir/src/attrs.rs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'crates/hir') diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index a027f881e..99fb65bac 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -10,8 +10,8 @@ use hir_ty::db::HirDatabase; use syntax::ast; use crate::{ - Adt, Const, Enum, Field, Function, GenericParam, MacroDef, Module, ModuleDef, Static, Struct, - Trait, TypeAlias, Union, Variant, + Adt, Const, ConstParam, Enum, Field, Function, GenericParam, LifetimeParam, MacroDef, Module, + ModuleDef, Static, Struct, Trait, TypeAlias, TypeParam, Union, Variant, }; pub trait HasAttrs { @@ -65,23 +65,24 @@ impl_has_attrs![ (GenericParam, GenericParamId), ]; -macro_rules! impl_has_attrs_adt { - ($($adt:ident),*) => {$( - impl HasAttrs for $adt { +macro_rules! impl_has_attrs_enum { + ($($variant:ident),* for $enum:ident) => {$( + impl HasAttrs for $variant { fn attrs(self, db: &dyn HirDatabase) -> Attrs { - Adt::$adt(self).attrs(db) + $enum::$variant(self).attrs(db) } fn docs(self, db: &dyn HirDatabase) -> Option { - Adt::$adt(self).docs(db) + $enum::$variant(self).docs(db) } fn resolve_doc_path(self, db: &dyn HirDatabase, link: &str, ns: Option) -> Option { - Adt::$adt(self).resolve_doc_path(db, link, ns) + $enum::$variant(self).resolve_doc_path(db, link, ns) } } )*}; } -impl_has_attrs_adt![Struct, Union, Enum]; +impl_has_attrs_enum![Struct, Union, Enum for Adt]; +impl_has_attrs_enum![TypeParam, ConstParam, LifetimeParam for GenericParam]; fn resolve_doc_path( db: &dyn HirDatabase, -- cgit v1.2.3