@@ -289,16 +289,18 @@ impl HirDisplay for ProjectionTy {
289
289
return write ! ( f, "{}" , TYPE_HINT_TRUNCATION ) ;
290
290
}
291
291
292
- let trait_ = f . db . trait_data ( self . trait_ ( f. db ) ) ;
292
+ let trait_ref = self . trait_ref ( f. db ) ;
293
293
write ! ( f, "<" ) ?;
294
- self . self_type_parameter ( f. db ) . hir_fmt ( f) ?;
295
- write ! ( f, " as {}" , trait_. name) ?;
296
- if self . substitution . len ( Interner ) > 1 {
294
+ fmt_trait_ref ( & trait_ref, f, true ) ?;
295
+ write ! ( f, ">::{}" , f. db. type_alias_data( from_assoc_type_id( self . associated_ty_id) ) . name) ?;
296
+ let proj_params_count =
297
+ self . substitution . len ( Interner ) - trait_ref. substitution . len ( Interner ) ;
298
+ let proj_params = & self . substitution . as_slice ( Interner ) [ ..proj_params_count] ;
299
+ if !proj_params. is_empty ( ) {
297
300
write ! ( f, "<" ) ?;
298
- f. write_joined ( & self . substitution . as_slice ( Interner ) [ 1 .. ] , ", " ) ?;
301
+ f. write_joined ( proj_params , ", " ) ?;
299
302
write ! ( f, ">" ) ?;
300
303
}
301
- write ! ( f, ">::{}" , f. db. type_alias_data( from_assoc_type_id( self . associated_ty_id) ) . name) ?;
302
304
Ok ( ( ) )
303
305
}
304
306
}
@@ -641,9 +643,12 @@ impl HirDisplay for Ty {
641
643
// Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
642
644
if f. display_target . is_test ( ) {
643
645
write ! ( f, "{}::{}" , trait_. name, type_alias_data. name) ?;
646
+ // Note that the generic args for the associated type come before those for the
647
+ // trait (including the self type).
648
+ // FIXME: reconsider the generic args order upon formatting?
644
649
if parameters. len ( Interner ) > 0 {
645
650
write ! ( f, "<" ) ?;
646
- f. write_joined ( & * parameters. as_slice ( Interner ) , ", " ) ?;
651
+ f. write_joined ( parameters. as_slice ( Interner ) , ", " ) ?;
647
652
write ! ( f, ">" ) ?;
648
653
}
649
654
} else {
@@ -972,9 +977,20 @@ fn write_bounds_like_dyn_trait(
972
977
angle_open = true ;
973
978
}
974
979
if let AliasTy :: Projection ( proj) = alias {
975
- let type_alias =
976
- f. db . type_alias_data ( from_assoc_type_id ( proj. associated_ty_id ) ) ;
977
- write ! ( f, "{} = " , type_alias. name) ?;
980
+ let assoc_ty_id = from_assoc_type_id ( proj. associated_ty_id ) ;
981
+ let type_alias = f. db . type_alias_data ( assoc_ty_id) ;
982
+ write ! ( f, "{}" , type_alias. name) ?;
983
+
984
+ let proj_arg_count = generics ( f. db . upcast ( ) , assoc_ty_id. into ( ) ) . len_self ( ) ;
985
+ if proj_arg_count > 0 {
986
+ write ! ( f, "<" ) ?;
987
+ f. write_joined (
988
+ & proj. substitution . as_slice ( Interner ) [ ..proj_arg_count] ,
989
+ ", " ,
990
+ ) ?;
991
+ write ! ( f, ">" ) ?;
992
+ }
993
+ write ! ( f, " = " ) ?;
978
994
}
979
995
ty. hir_fmt ( f) ?;
980
996
}
0 commit comments