From 643bbf15a2a76e7241156249261bf0d060deecd4 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 6 Oct 2020 14:40:27 +0200 Subject: Fix trait object hir formatting behind pointer and references --- crates/hir_ty/src/display.rs | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index f389c5a4b..d2e151f25 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -221,7 +221,16 @@ impl HirDisplay for ApplicationTy { } TypeCtor::RawPtr(m) => { let t = self.parameters.as_single(); - write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?; + let ty_display = t.display(f.db); + + write!(f, "*{}", m.as_keyword_for_ptr())?; + if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { + write!(f, "(")?; + write!(f, "{}", ty_display)?; + write!(f, ")")?; + } else { + write!(f, "{}", ty_display)?; + } } TypeCtor::Ref(m) => { let t = self.parameters.as_single(); @@ -230,7 +239,15 @@ impl HirDisplay for ApplicationTy { } else { t.display(f.db) }; - write!(f, "&{}{}", m.as_keyword_for_ref(), ty_display)?; + + write!(f, "&{}", m.as_keyword_for_ref())?; + if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) { + write!(f, "(")?; + write!(f, "{}", ty_display)?; + write!(f, ")")?; + } else { + write!(f, "{}", ty_display)?; + } } TypeCtor::Never => write!(f, "!")?, TypeCtor::Tuple { .. } => { @@ -636,14 +653,14 @@ impl HirDisplay for GenericPredicate { impl HirDisplay for Obligation { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { - Ok(match self { - Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db))?, + match self { + Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), Obligation::Projection(proj) => write!( f, "Normalize({} => {})", proj.projection_ty.display(f.db), proj.ty.display(f.db) - )?, - }) + ), + } } } -- cgit v1.2.3