From 11f86641829273e2b2b7023c2028bb475fce58ee Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 11 Dec 2020 13:49:32 +0100 Subject: Add Lifetimes to the HIR --- crates/hir_ty/src/display.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty/src/display.rs') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index e77481906..0d968cc68 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -4,7 +4,7 @@ use std::fmt; use crate::{ db::HirDatabase, utils::generics, ApplicationTy, CallableDefId, FnSig, GenericPredicate, - Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, + Lifetime, Obligation, OpaqueTyId, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, }; use hir_def::{ find_path, generics::TypeParamProvenance, item_scope::ItemInNs, AdtId, AssocContainerId, @@ -710,6 +710,19 @@ impl HirDisplay for GenericPredicate { } } +impl HirDisplay for Lifetime { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + match self { + Lifetime::Parameter(id) => { + let generics = generics(f.db.upcast(), id.parent); + let param_data = &generics.params.lifetimes[id.local_id]; + write!(f, "{}", ¶m_data.name) + } + Lifetime::Static => write!(f, "'static"), + } + } +} + impl HirDisplay for Obligation { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { match self { -- cgit v1.2.3