aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/hir_ty/src/display.rs49
1 files changed, 17 insertions, 32 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 8fe4ed3fa..9e6bbcdf1 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -51,6 +51,10 @@ pub trait HirDisplay {
51 where 51 where
52 Self: Sized, 52 Self: Sized,
53 { 53 {
54 assert!(
55 !matches!(display_target, DisplayTarget::SourceCode { .. }),
56 "HirDisplayWrapper cannot fail with DisplaySourceCodeError, use HirDisplay::hir_fmt directly instead"
57 );
54 HirDisplayWrapper { db, t: self, max_size, omit_verbose_types, display_target } 58 HirDisplayWrapper { db, t: self, max_size, omit_verbose_types, display_target }
55 } 59 }
56 60
@@ -235,7 +239,7 @@ where
235 Err(HirDisplayError::FmtError) => Err(fmt::Error), 239 Err(HirDisplayError::FmtError) => Err(fmt::Error),
236 Err(HirDisplayError::DisplaySourceCodeError(_)) => { 240 Err(HirDisplayError::DisplaySourceCodeError(_)) => {
237 // This should never happen 241 // This should never happen
238 panic!("HirDisplay failed when calling Display::fmt!") 242 panic!("HirDisplay::hir_fmt failed with DisplaySourceCodeError when calling Display::fmt!")
239 } 243 }
240 } 244 }
241 } 245 }
@@ -256,13 +260,9 @@ impl HirDisplay for ProjectionTy {
256 } 260 }
257 261
258 let trait_ = f.db.trait_data(self.trait_(f.db)); 262 let trait_ = f.db.trait_data(self.trait_(f.db));
259 let first_parameter = self.self_type_parameter(&Interner).into_displayable( 263 write!(f, "<")?;
260 f.db, 264 self.self_type_parameter(&Interner).hir_fmt(f)?;
261 f.max_size, 265 write!(f, " as {}", trait_.name)?;
262 f.omit_verbose_types,
263 f.display_target,
264 );
265 write!(f, "<{} as {}", first_parameter, trait_.name)?;
266 if self.substitution.len(&Interner) > 1 { 266 if self.substitution.len(&Interner) > 1 {
267 write!(f, "<")?; 267 write!(f, "<")?;
268 f.write_joined(&self.substitution.interned()[1..], ", ")?; 268 f.write_joined(&self.substitution.interned()[1..], ", ")?;
@@ -341,9 +341,6 @@ impl HirDisplay for Ty {
341 write!(f, "]")?; 341 write!(f, "]")?;
342 } 342 }
343 TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => { 343 TyKind::Raw(m, t) | TyKind::Ref(m, _, t) => {
344 let ty_display =
345 t.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target);
346
347 if matches!(self.kind(&Interner), TyKind::Raw(..)) { 344 if matches!(self.kind(&Interner), TyKind::Raw(..)) {
348 write!( 345 write!(
349 f, 346 f,
@@ -398,16 +395,16 @@ impl HirDisplay for Ty {
398 if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_) 395 if fn_traits(f.db.upcast(), trait_).any(|it| it == trait_)
399 && predicates.len() <= 2 396 && predicates.len() <= 2
400 { 397 {
401 return write!(f, "{}", ty_display); 398 return t.hir_fmt(f);
402 } 399 }
403 } 400 }
404 401
405 if predicates.len() > 1 { 402 if predicates.len() > 1 {
406 write!(f, "(")?; 403 write!(f, "(")?;
407 write!(f, "{}", ty_display)?; 404 t.hir_fmt(f)?;
408 write!(f, ")")?; 405 write!(f, ")")?;
409 } else { 406 } else {
410 write!(f, "{}", ty_display)?; 407 t.hir_fmt(f)?;
411 } 408 }
412 } 409 }
413 TyKind::Tuple(_, substs) => { 410 TyKind::Tuple(_, substs) => {
@@ -454,14 +451,8 @@ impl HirDisplay for Ty {
454 write!(f, ")")?; 451 write!(f, ")")?;
455 let ret = sig.ret(); 452 let ret = sig.ret();
456 if !ret.is_unit() { 453 if !ret.is_unit() {
457 let ret_display = ret.into_displayable( 454 write!(f, " -> ")?;
458 f.db, 455 ret.hir_fmt(f)?;
459 f.max_size,
460 f.omit_verbose_types,
461 f.display_target,
462 );
463
464 write!(f, " -> {}", ret_display)?;
465 } 456 }
466 } 457 }
467 TyKind::Adt(AdtId(def_id), parameters) => { 458 TyKind::Adt(AdtId(def_id), parameters) => {
@@ -603,13 +594,8 @@ impl HirDisplay for Ty {
603 write!(f, "|")?; 594 write!(f, "|")?;
604 }; 595 };
605 596
606 let ret_display = sig.ret().into_displayable( 597 write!(f, " -> ")?;
607 f.db, 598 sig.ret().hir_fmt(f)?;
608 f.max_size,
609 f.omit_verbose_types,
610 f.display_target,
611 );
612 write!(f, " -> {}", ret_display)?;
613 } else { 599 } else {
614 write!(f, "{{closure}}")?; 600 write!(f, "{{closure}}")?;
615 } 601 }
@@ -697,9 +683,8 @@ impl HirDisplay for CallableSig {
697 write!(f, ")")?; 683 write!(f, ")")?;
698 let ret = self.ret(); 684 let ret = self.ret();
699 if !ret.is_unit() { 685 if !ret.is_unit() {
700 let ret_display = 686 write!(f, " -> ")?;
701 ret.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); 687 ret.hir_fmt(f)?;
702 write!(f, " -> {}", ret_display)?;
703 } 688 }
704 Ok(()) 689 Ok(())
705 } 690 }