From 4d1e1daa31239cb71a81c6958c1b9137274fd189 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 16 Mar 2021 16:36:34 +0100 Subject: Implement HirDisplay for some more types --- crates/hir/src/display.rs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'crates/hir/src') diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 44cdcc296..81f0e04e5 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -12,8 +12,8 @@ use hir_ty::display::{ use syntax::ast::{self, NameOwner}; use crate::{ - Const, ConstParam, Enum, Field, Function, HasVisibility, Module, Static, Struct, Substs, Trait, - Type, TypeAlias, TypeParam, Union, Variant, + Adt, Const, ConstParam, Enum, Field, Function, GenericParam, HasVisibility, LifetimeParam, + Module, Static, Struct, Substs, Trait, Type, TypeAlias, TypeParam, Union, Variant, }; impl HirDisplay for Function { @@ -120,6 +120,16 @@ impl HirDisplay for Function { } } +impl HirDisplay for Adt { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + match self { + Adt::Struct(it) => it.hir_fmt(f), + Adt::Union(it) => it.hir_fmt(f), + Adt::Enum(it) => it.hir_fmt(f), + } + } +} + impl HirDisplay for Struct { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write_visibility(self.module(f.db).id, self.visibility(f.db), f)?; @@ -211,6 +221,16 @@ impl HirDisplay for Type { } } +impl HirDisplay for GenericParam { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + match self { + GenericParam::TypeParam(it) => it.hir_fmt(f), + GenericParam::LifetimeParam(it) => it.hir_fmt(f), + GenericParam::ConstParam(it) => it.hir_fmt(f), + } + } +} + impl HirDisplay for TypeParam { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write!(f, "{}", self.name(f.db))?; @@ -224,6 +244,12 @@ impl HirDisplay for TypeParam { } } +impl HirDisplay for LifetimeParam { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + write!(f, "{}", self.name(f.db)) + } +} + impl HirDisplay for ConstParam { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { write!(f, "const {}: ", self.name(f.db))?; -- cgit v1.2.3