From d587ca2991406bd348768b2912c3cb66c869e7e8 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 5 Apr 2021 20:46:15 +0200 Subject: Replace unused hir_ty::Lifetime with chalk equivalents --- crates/hir_ty/src/display.rs | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) (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 f31e6b108..01c7ef91f 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -1,8 +1,10 @@ //! FIXME: write short doc here -use std::{array, fmt}; +use std::{ + array, + fmt::{self, Debug}, +}; -use chalk_ir::Mutability; use hir_def::{ db::DefDatabase, find_path, @@ -16,9 +18,10 @@ use hir_def::{ use hir_expand::name::Name; use crate::{ - db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, - to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, - CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy, + db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, + lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk, + utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg, + ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy, ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, }; @@ -827,15 +830,35 @@ impl HirDisplay for WhereClause { } } +impl HirDisplay for LifetimeOutlives { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + self.a.hir_fmt(f)?; + write!(f, ": ")?; + self.b.hir_fmt(f) + } +} + impl HirDisplay for Lifetime { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + self.interned().hir_fmt(f) + } +} + +impl HirDisplay for LifetimeData { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { match self { - Lifetime::Parameter(id) => { + LifetimeData::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index), + LifetimeData::InferenceVar(_) => write!(f, "_"), + LifetimeData::Placeholder(idx) => { + let id = lt_from_placeholder_idx(f.db, *idx); let generics = generics(f.db.upcast(), id.parent); let param_data = &generics.params.lifetimes[id.local_id]; - write!(f, "{}", ¶m_data.name) + write!(f, "{}", param_data.name) } - Lifetime::Static => write!(f, "'static"), + LifetimeData::Static => write!(f, "'static"), + LifetimeData::Empty(_) => Ok(()), + LifetimeData::Erased => Ok(()), + LifetimeData::Phantom(_, _) => Ok(()), } } } -- cgit v1.2.3