diff options
Diffstat (limited to 'crates/hir_ty/src/display.rs')
-rw-r--r-- | crates/hir_ty/src/display.rs | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index c6b4f37e5..59a1bd9b0 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -18,9 +18,9 @@ use hir_expand::name::Name; | |||
18 | 18 | ||
19 | use crate::{ | 19 | use crate::{ |
20 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, | 20 | db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, |
21 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasTy, CallableDefId, | 21 | to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, |
22 | CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, OpaqueTy, | 22 | CallableDefId, CallableSig, GenericPredicate, ImplTraitId, Interner, Lifetime, Obligation, |
23 | ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, | 23 | OpaqueTy, ProjectionTy, Scalar, Substitution, TraitRef, Ty, TyKind, |
24 | }; | 24 | }; |
25 | 25 | ||
26 | pub struct HirFormatter<'a> { | 26 | pub struct HirFormatter<'a> { |
@@ -268,6 +268,16 @@ impl HirDisplay for ProjectionTy { | |||
268 | } | 268 | } |
269 | } | 269 | } |
270 | 270 | ||
271 | impl HirDisplay for OpaqueTy { | ||
272 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
273 | if f.should_truncate() { | ||
274 | return write!(f, "{}", TYPE_HINT_TRUNCATION); | ||
275 | } | ||
276 | |||
277 | self.substitution[0].hir_fmt(f) | ||
278 | } | ||
279 | } | ||
280 | |||
271 | impl HirDisplay for Ty { | 281 | impl HirDisplay for Ty { |
272 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | 282 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { |
273 | if f.should_truncate() { | 283 | if f.should_truncate() { |
@@ -700,12 +710,12 @@ fn write_bounds_like_dyn_trait( | |||
700 | } | 710 | } |
701 | } | 711 | } |
702 | } | 712 | } |
703 | GenericPredicate::Projection(projection_pred) if is_fn_trait => { | 713 | GenericPredicate::AliasEq(alias_eq) if is_fn_trait => { |
704 | is_fn_trait = false; | 714 | is_fn_trait = false; |
705 | write!(f, " -> ")?; | 715 | write!(f, " -> ")?; |
706 | projection_pred.ty.hir_fmt(f)?; | 716 | alias_eq.ty.hir_fmt(f)?; |
707 | } | 717 | } |
708 | GenericPredicate::Projection(projection_pred) => { | 718 | GenericPredicate::AliasEq(AliasEq { ty, alias }) => { |
709 | // in types in actual Rust, these will always come | 719 | // in types in actual Rust, these will always come |
710 | // after the corresponding Implemented predicate | 720 | // after the corresponding Implemented predicate |
711 | if angle_open { | 721 | if angle_open { |
@@ -714,11 +724,12 @@ fn write_bounds_like_dyn_trait( | |||
714 | write!(f, "<")?; | 724 | write!(f, "<")?; |
715 | angle_open = true; | 725 | angle_open = true; |
716 | } | 726 | } |
717 | let type_alias = f.db.type_alias_data(from_assoc_type_id( | 727 | if let AliasTy::Projection(proj) = alias { |
718 | projection_pred.projection_ty.associated_ty_id, | 728 | let type_alias = |
719 | )); | 729 | f.db.type_alias_data(from_assoc_type_id(proj.associated_ty_id)); |
720 | write!(f, "{} = ", type_alias.name)?; | 730 | write!(f, "{} = ", type_alias.name)?; |
721 | projection_pred.ty.hir_fmt(f)?; | 731 | } |
732 | ty.hir_fmt(f)?; | ||
722 | } | 733 | } |
723 | GenericPredicate::Error => { | 734 | GenericPredicate::Error => { |
724 | if angle_open { | 735 | if angle_open { |
@@ -775,20 +786,20 @@ impl HirDisplay for GenericPredicate { | |||
775 | 786 | ||
776 | match self { | 787 | match self { |
777 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, | 788 | GenericPredicate::Implemented(trait_ref) => trait_ref.hir_fmt(f)?, |
778 | GenericPredicate::Projection(projection_pred) => { | 789 | GenericPredicate::AliasEq(AliasEq { |
790 | alias: AliasTy::Projection(projection_ty), | ||
791 | ty, | ||
792 | }) => { | ||
779 | write!(f, "<")?; | 793 | write!(f, "<")?; |
780 | projection_pred.projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; | 794 | projection_ty.trait_ref(f.db).hir_fmt_ext(f, true)?; |
781 | write!( | 795 | write!( |
782 | f, | 796 | f, |
783 | ">::{} = ", | 797 | ">::{} = ", |
784 | f.db.type_alias_data(from_assoc_type_id( | 798 | f.db.type_alias_data(from_assoc_type_id(projection_ty.associated_ty_id)).name, |
785 | projection_pred.projection_ty.associated_ty_id | ||
786 | )) | ||
787 | .name, | ||
788 | )?; | 799 | )?; |
789 | projection_pred.ty.hir_fmt(f)?; | 800 | ty.hir_fmt(f)?; |
790 | } | 801 | } |
791 | GenericPredicate::Error => write!(f, "{{error}}")?, | 802 | GenericPredicate::AliasEq(_) | GenericPredicate::Error => write!(f, "{{error}}")?, |
792 | } | 803 | } |
793 | Ok(()) | 804 | Ok(()) |
794 | } | 805 | } |
@@ -815,11 +826,14 @@ impl HirDisplay for Obligation { | |||
815 | tr.hir_fmt(f)?; | 826 | tr.hir_fmt(f)?; |
816 | write!(f, ")") | 827 | write!(f, ")") |
817 | } | 828 | } |
818 | Obligation::Projection(proj) => { | 829 | Obligation::AliasEq(AliasEq { alias, ty }) => { |
819 | write!(f, "Normalize(")?; | 830 | write!(f, "Normalize(")?; |
820 | proj.projection_ty.hir_fmt(f)?; | 831 | match alias { |
832 | AliasTy::Projection(projection_ty) => projection_ty.hir_fmt(f)?, | ||
833 | AliasTy::Opaque(opaque) => opaque.hir_fmt(f)?, | ||
834 | } | ||
821 | write!(f, " => ")?; | 835 | write!(f, " => ")?; |
822 | proj.ty.hir_fmt(f)?; | 836 | ty.hir_fmt(f)?; |
823 | write!(f, ")") | 837 | write!(f, ")") |
824 | } | 838 | } |
825 | } | 839 | } |