From 86feac18e8f96a99830defd707eb221f12d02924 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 7 Apr 2021 20:26:27 +0200 Subject: Change TraitRef::hir_fmt_ext to free-standing function --- crates/hir_ty/src/display.rs | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 9e6bbcdf1..266016786 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -792,31 +792,29 @@ fn write_bounds_like_dyn_trait( Ok(()) } -impl TraitRef { - fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { - if f.should_truncate() { - return write!(f, "{}", TYPE_HINT_TRUNCATION); - } +fn fmt_trait_ref(tr: &TraitRef, f: &mut HirFormatter, use_as: bool) -> Result<(), HirDisplayError> { + if f.should_truncate() { + return write!(f, "{}", TYPE_HINT_TRUNCATION); + } - self.self_type_parameter(&Interner).hir_fmt(f)?; - if use_as { - write!(f, " as ")?; - } else { - write!(f, ": ")?; - } - write!(f, "{}", f.db.trait_data(self.hir_trait_id()).name)?; - if self.substitution.len(&Interner) > 1 { - write!(f, "<")?; - f.write_joined(&self.substitution.interned()[1..], ", ")?; - write!(f, ">")?; - } - Ok(()) + tr.self_type_parameter(&Interner).hir_fmt(f)?; + if use_as { + write!(f, " as ")?; + } else { + write!(f, ": ")?; } + write!(f, "{}", f.db.trait_data(tr.hir_trait_id()).name)?; + if tr.substitution.len(&Interner) > 1 { + write!(f, "<")?; + f.write_joined(&tr.substitution.interned()[1..], ", ")?; + write!(f, ">")?; + } + Ok(()) } impl HirDisplay for TraitRef { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { - self.hir_fmt_ext(f, false) + fmt_trait_ref(self, f, false) } } @@ -830,7 +828,7 @@ impl HirDisplay for WhereClause { WhereClause::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, WhereClause::AliasEq(AliasEq { alias: AliasTy::Projection(projection_ty), ty }) => { write!(f, "<")?; - projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; + fmt_trait_ref(&projection_ty.trait_ref(f.db), f, true)?; write!( f, ">::{} = ", -- cgit v1.2.3