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.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index ee15f4f52..b7e85e024 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -11,7 +11,8 @@ use hir_def::{
11use hir_expand::name::Name; 11use hir_expand::name::Name;
12 12
13use crate::{ 13use crate::{
14 db::HirDatabase, primitive, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig, 14 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, primitive, to_assoc_type_id,
15 traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, CallableSig,
15 GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar, 16 GenericPredicate, Interner, Lifetime, Obligation, OpaqueTy, OpaqueTyId, ProjectionTy, Scalar,
16 Substs, TraitRef, Ty, TyKind, 17 Substs, TraitRef, Ty, TyKind,
17}; 18};
@@ -256,7 +257,7 @@ impl HirDisplay for ProjectionTy {
256 f.write_joined(&self.parameters[1..], ", ")?; 257 f.write_joined(&self.parameters[1..], ", ")?;
257 write!(f, ">")?; 258 write!(f, ">")?;
258 } 259 }
259 write!(f, ">::{}", f.db.type_alias_data(self.associated_ty).name)?; 260 write!(f, ">::{}", f.db.type_alias_data(from_assoc_type_id(self.associated_ty)).name)?;
260 Ok(()) 261 Ok(())
261 } 262 }
262} 263}
@@ -363,7 +364,7 @@ impl HirDisplay for Ty {
363 sig.hir_fmt(f)?; 364 sig.hir_fmt(f)?;
364 } 365 }
365 TyKind::FnDef(def, parameters) => { 366 TyKind::FnDef(def, parameters) => {
366 let def = *def; 367 let def = from_chalk(f.db, *def);
367 let sig = f.db.callable_item_signature(def).subst(parameters); 368 let sig = f.db.callable_item_signature(def).subst(parameters);
368 match def { 369 match def {
369 CallableDefId::FunctionId(ff) => { 370 CallableDefId::FunctionId(ff) => {
@@ -431,7 +432,7 @@ impl HirDisplay for Ty {
431 || f.omit_verbose_types() 432 || f.omit_verbose_types()
432 { 433 {
433 match self 434 match self
434 .as_generic_def() 435 .as_generic_def(f.db)
435 .map(|generic_def_id| f.db.generic_defaults(generic_def_id)) 436 .map(|generic_def_id| f.db.generic_defaults(generic_def_id))
436 .filter(|defaults| !defaults.is_empty()) 437 .filter(|defaults| !defaults.is_empty())
437 { 438 {
@@ -467,13 +468,14 @@ impl HirDisplay for Ty {
467 } 468 }
468 } 469 }
469 } 470 }
470 TyKind::AssociatedType(type_alias, parameters) => { 471 TyKind::AssociatedType(assoc_type_id, parameters) => {
472 let type_alias = from_assoc_type_id(*assoc_type_id);
471 let trait_ = match type_alias.lookup(f.db.upcast()).container { 473 let trait_ = match type_alias.lookup(f.db.upcast()).container {
472 AssocContainerId::TraitId(it) => it, 474 AssocContainerId::TraitId(it) => it,
473 _ => panic!("not an associated type"), 475 _ => panic!("not an associated type"),
474 }; 476 };
475 let trait_ = f.db.trait_data(trait_); 477 let trait_ = f.db.trait_data(trait_);
476 let type_alias_data = f.db.type_alias_data(*type_alias); 478 let type_alias_data = f.db.type_alias_data(type_alias);
477 479
478 // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) 480 // 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() { 481 if f.display_target.is_test() {
@@ -484,14 +486,16 @@ impl HirDisplay for Ty {
484 write!(f, ">")?; 486 write!(f, ">")?;
485 } 487 }
486 } else { 488 } else {
487 let projection_ty = 489 let projection_ty = ProjectionTy {
488 ProjectionTy { associated_ty: *type_alias, parameters: parameters.clone() }; 490 associated_ty: to_assoc_type_id(type_alias),
491 parameters: parameters.clone(),
492 };
489 493
490 projection_ty.hir_fmt(f)?; 494 projection_ty.hir_fmt(f)?;
491 } 495 }
492 } 496 }
493 TyKind::ForeignType(type_alias) => { 497 TyKind::ForeignType(type_alias) => {
494 let type_alias = f.db.type_alias_data(*type_alias); 498 let type_alias = f.db.type_alias_data(from_foreign_def_id(*type_alias));
495 write!(f, "{}", type_alias.name)?; 499 write!(f, "{}", type_alias.name)?;
496 } 500 }
497 TyKind::OpaqueType(opaque_ty_id, parameters) => { 501 TyKind::OpaqueType(opaque_ty_id, parameters) => {
@@ -697,7 +701,9 @@ fn write_bounds_like_dyn_trait(
697 write!(f, "<")?; 701 write!(f, "<")?;
698 angle_open = true; 702 angle_open = true;
699 } 703 }
700 let type_alias = f.db.type_alias_data(projection_pred.projection_ty.associated_ty); 704 let type_alias = f.db.type_alias_data(from_assoc_type_id(
705 projection_pred.projection_ty.associated_ty,
706 ));
701 write!(f, "{} = ", type_alias.name)?; 707 write!(f, "{} = ", type_alias.name)?;
702 projection_pred.ty.hir_fmt(f)?; 708 projection_pred.ty.hir_fmt(f)?;
703 } 709 }
@@ -768,7 +774,10 @@ impl HirDisplay for GenericPredicate {
768 write!( 774 write!(
769 f, 775 f,
770 ">::{} = ", 776 ">::{} = ",
771 f.db.type_alias_data(projection_pred.projection_ty.associated_ty).name, 777 f.db.type_alias_data(from_assoc_type_id(
778 projection_pred.projection_ty.associated_ty
779 ))
780 .name,
772 )?; 781 )?;
773 projection_pred.ty.hir_fmt(f)?; 782 projection_pred.ty.hir_fmt(f)?;
774 } 783 }