@@ -18,9 +18,9 @@ use hir_expand::name::Name;
1818
1919use crate :: {
2020 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 ,
22- CallableSig , GenericPredicate , ImplTraitId , Interner , Lifetime , Obligation , OpaqueTy ,
23- ProjectionTy , Scalar , Substitution , TraitRef , Ty , TyKind ,
21+ to_assoc_type_id, traits:: chalk:: from_chalk, utils:: generics, AdtId , AliasEq , AliasTy ,
22+ CallableDefId , CallableSig , GenericPredicate , ImplTraitId , Interner , Lifetime , Obligation ,
23+ OpaqueTy , ProjectionTy , Scalar , Substitution , TraitRef , Ty , TyKind ,
2424} ;
2525
2626pub struct HirFormatter < ' a > {
@@ -268,6 +268,16 @@ impl HirDisplay for ProjectionTy {
268268 }
269269}
270270
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+
271281impl HirDisplay for Ty {
272282 fn hir_fmt ( & self , f : & mut HirFormatter ) -> Result < ( ) , HirDisplayError > {
273283 if f. should_truncate ( ) {
@@ -700,12 +710,12 @@ fn write_bounds_like_dyn_trait(
700710 }
701711 }
702712 }
703- GenericPredicate :: Projection ( projection_pred ) if is_fn_trait => {
713+ GenericPredicate :: AliasEq ( alias_eq ) if is_fn_trait => {
704714 is_fn_trait = false ;
705715 write ! ( f, " -> " ) ?;
706- projection_pred . ty . hir_fmt ( f) ?;
716+ alias_eq . ty . hir_fmt ( f) ?;
707717 }
708- GenericPredicate :: Projection ( projection_pred ) => {
718+ GenericPredicate :: AliasEq ( AliasEq { ty , alias } ) => {
709719 // in types in actual Rust, these will always come
710720 // after the corresponding Implemented predicate
711721 if angle_open {
@@ -714,11 +724,12 @@ fn write_bounds_like_dyn_trait(
714724 write ! ( f, "<" ) ?;
715725 angle_open = true ;
716726 }
717- let type_alias = f. db . type_alias_data ( from_assoc_type_id (
718- projection_pred. projection_ty . associated_ty_id ,
719- ) ) ;
720- write ! ( f, "{} = " , type_alias. name) ?;
721- projection_pred. ty . hir_fmt ( f) ?;
727+ if let AliasTy :: Projection ( proj) = alias {
728+ let type_alias =
729+ f. db . type_alias_data ( from_assoc_type_id ( proj. associated_ty_id ) ) ;
730+ write ! ( f, "{} = " , type_alias. name) ?;
731+ }
732+ ty. hir_fmt ( f) ?;
722733 }
723734 GenericPredicate :: Error => {
724735 if angle_open {
@@ -775,20 +786,20 @@ impl HirDisplay for GenericPredicate {
775786
776787 match self {
777788 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+ } ) => {
779793 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 ) ?;
781795 write ! (
782796 f,
783797 ">::{} = " ,
784- f. db. type_alias_data( from_assoc_type_id(
785- projection_pred. projection_ty. associated_ty_id
786- ) )
787- . name,
798+ f. db. type_alias_data( from_assoc_type_id( projection_ty. associated_ty_id) ) . name,
788799 ) ?;
789- projection_pred . ty . hir_fmt ( f) ?;
800+ ty. hir_fmt ( f) ?;
790801 }
791- GenericPredicate :: Error => write ! ( f, "{{error}}" ) ?,
802+ GenericPredicate :: AliasEq ( _ ) | GenericPredicate :: Error => write ! ( f, "{{error}}" ) ?,
792803 }
793804 Ok ( ( ) )
794805 }
@@ -815,11 +826,14 @@ impl HirDisplay for Obligation {
815826 tr. hir_fmt ( f) ?;
816827 write ! ( f, ")" )
817828 }
818- Obligation :: Projection ( proj ) => {
829+ Obligation :: AliasEq ( AliasEq { alias , ty } ) => {
819830 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+ }
821835 write ! ( f, " => " ) ?;
822- proj . ty . hir_fmt ( f) ?;
836+ ty. hir_fmt ( f) ?;
823837 write ! ( f, ")" )
824838 }
825839 }
0 commit comments