From ffdb2da49d08384368fbc50d4f60a8dfd2ab70ee Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 6 Apr 2021 14:16:07 +0200 Subject: Don't use HirDisplayWrapper when displaying SourceCode --- crates/hir_ty/src/display.rs | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 8fe4ed3fa..4af2bcf7a 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -256,13 +256,9 @@ impl HirDisplay for ProjectionTy { } let trait_ = f.db.trait_data(self.trait_(f.db)); - let first_parameter = self.self_type_parameter(&Interner).into_displayable( - f.db, - f.max_size, - f.omit_verbose_types, - f.display_target, - ); - write!(f, "<{} as {}", first_parameter, trait_.name)?; + write!(f, "<")?; + self.self_type_parameter(&Interner).hir_fmt(f)?; + write!(f, " as {}", trait_.name)?; if self.substitution.len(&Interner) > 1 { write!(f, "<")?; f.write_joined(&self.substitution.interned()[1..], ", ")?; @@ -341,9 +337,6 @@ impl HirDisplay for Ty { write!(f, "]")?; } TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => { - let ty_display = - t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); - if matches!(self.kind(&Interner), TyKind::Raw(..)) { write!( f, @@ -398,16 +391,16 @@ impl HirDisplay for Ty { if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) && predicates.len() <= 2 { - return write!(f, "{}", ty_display); + return t.hir_fmt(f); } } if predicates.len() > 1 { write!(f, "(")?; - write!(f, "{}", ty_display)?; + t.hir_fmt(f)?; write!(f, ")")?; } else { - write!(f, "{}", ty_display)?; + t.hir_fmt(f)?; } } TyKind::Tuple(_, substs) => { @@ -454,14 +447,8 @@ impl HirDisplay for Ty { write!(f, ")")?; let ret = sig.ret(); if !ret.is_unit() { - let ret_display = ret.into_displayable( - f.db, - f.max_size, - f.omit_verbose_types, - f.display_target, - ); - - write!(f, " -> {}", ret_display)?; + write!(f, " -> ")?; + ret.hir_fmt(f)?; } } TyKind::Adt(AdtId(def_id), parameters) => { @@ -603,13 +590,8 @@ impl HirDisplay for Ty { write!(f, "|")?; }; - let ret_display = sig.ret().into_displayable( - f.db, - f.max_size, - f.omit_verbose_types, - f.display_target, - ); - write!(f, " -> {}", ret_display)?; + write!(f, " -> ")?; + sig.ret().hir_fmt(f)?; } else { write!(f, "{{closure}}")?; } @@ -697,9 +679,8 @@ impl HirDisplay for CallableSig { write!(f, ")")?; let ret = self.ret(); if !ret.is_unit() { - let ret_display = - ret.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); - write!(f, " -> {}", ret_display)?; + write!(f, " -> ")?; + ret.hir_fmt(f)?; } Ok(()) } -- cgit v1.2.3 From a43409fa4313938be21c8650eb2f523fefdcb508 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 6 Apr 2021 14:42:34 +0200 Subject: Panic when creating a HirDisplayWrapper with DisplayTarget::SourceCode --- crates/hir_ty/src/display.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 4af2bcf7a..9e6bbcdf1 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -51,6 +51,10 @@ pub trait HirDisplay { where Self: Sized, { + assert!( + !matches!(display_target, DisplayTarget::SourceCode { .. }), + "HirDisplayWrapper cannot fail with DisplaySourceCodeError, use HirDisplay::hir_fmt directly instead" + ); HirDisplayWrapper { db, t: self, max_size, omit_verbose_types, display_target } } @@ -235,7 +239,7 @@ where Err(HirDisplayError::FmtError) => Err(fmt::Error), Err(HirDisplayError::DisplaySourceCodeError(_)) => { // This should never happen - panic!("HirDisplay failed when calling Display::fmt!") + panic!("HirDisplay::hir_fmt failed with DisplaySourceCodeError when calling Display::fmt!") } } } -- cgit v1.2.3