aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/display.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r--crates/hir_ty/src/display.rs28
1 files changed, 18 insertions, 10 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index 9b1e2ad05..2022069d8 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -11,9 +11,9 @@ use hir_def::{
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
13use crate::{ 13use crate::{
14 db::HirDatabase, from_foreign_def_id, primitive, utils::generics, AdtId, AliasTy, 14 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id,
15 CallableDefId, CallableSig, GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, 15 utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, GenericPredicate, Interner,
16 OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind, 16 Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, Substs, TraitRef, Ty, TyKind,
17}; 17};
18 18
19pub struct HirFormatter<'a> { 19pub struct HirFormatter<'a> {
@@ -256,7 +256,7 @@ impl HirDisplay for ProjectionTy {
256 f.write_joined(&self.parameters[1..], ", ")?; 256 f.write_joined(&self.parameters[1..], ", ")?;
257 write!(f, ">")?; 257 write!(f, ">")?;
258 } 258 }
259 write!(f, ">::{}", f.db.type_alias_data(self.associated_ty).name)?; 259 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?;
260 Ok(()) 260 Ok(())
261 } 261 }
262} 262}
@@ -467,13 +467,14 @@ impl HirDisplay for Ty {
467 } 467 }
468 } 468 }
469 } 469 }
470 TyKind::AssociatedType(type_alias, parameters) => { 470 TyKind::AssociatedType(assoc_type_id, parameters) => {
471 let type_alias = from_assoc_type_id(*assoc_type_id);
471 let trait_ = match type_alias.lookup(f.db.upcast()).container { 472 let trait_ = match type_alias.lookup(f.db.upcast()).container {
472 AssocContainerId::TraitId(it) => it, 473 AssocContainerId::TraitId(it) => it,
473 _ => panic!("not an associated type"), 474 _ => panic!("not an associated type"),
474 }; 475 };
475 let trait_ = f.db.trait_data(trait_); 476 let trait_ = f.db.trait_data(trait_);
476 let type_alias_data = f.db.type_alias_data(*type_alias); 477 let type_alias_data = f.db.type_alias_data(type_alias);
477 478
478 // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) 479 // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
479 if f.display_target.is_test() { 480 if f.display_target.is_test() {
@@ -484,8 +485,10 @@ impl HirDisplay for Ty {
484 write!(f, ">")?; 485 write!(f, ">")?;
485 } 486 }
486 } else { 487 } else {
487 let projection_ty = 488 let projection_ty = ProjectionTy {
488 ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() }; 489 associated_ty: to_assoc_type_id(type_alias),
490 parameters: parameters.clone(),
491 };
489 492
490 projection_ty.hir_fmt(f)?; 493 projection_ty.hir_fmt(f)?;
491 } 494 }
@@ -697,7 +700,9 @@ fn write_bounds_like_dyn_trait(
697 write!(f, "<")?; 700 write!(f, "<")?;
698 angle_open = true; 701 angle_open = true;
699 } 702 }
700 let type_alias = f.db.type_alias_data(projection_pred.projection_ty.associated_ty); 703 let type_alias = f.db.type_alias_data(from_assoc_type_id(
704 projection_pred.projection_ty.associated_ty,
705 ));
701 write!(f, "{} = ", type_alias.name)?; 706 write!(f, "{} = ", type_alias.name)?;
702 projection_pred.ty.hir_fmt(f)?; 707 projection_pred.ty.hir_fmt(f)?;
703 } 708 }
@@ -768,7 +773,10 @@ impl HirDisplay for GenericPredicate {
768 write!( 773 write!(
769 f, 774 f,
770 ">::{} = ", 775 ">::{} = ",
771 f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name, 776 f.db.type_alias_data(from_assoc_type_id(
777 projection_pred.projection_ty.associated_ty
778 ))
779 .name,
772 )?; 780 )?;
773 projection_pred.ty.hir_fmt(f)?; 781 projection_pred.ty.hir_fmt(f)?;
774 } 782 }