@@ -289,16 +289,18 @@ impl HirDisplay for ProjectionTy {
289289            return  write ! ( f,  "{}" ,  TYPE_HINT_TRUNCATION ) ; 
290290        } 
291291
292-         let  trait_  = f . db . trait_data ( self . trait_ ( f. db ) ) ; 
292+         let  trait_ref  = self . trait_ref ( f. db ) ; 
293293        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 ( )  { 
297300            write ! ( f,  "<" ) ?; 
298-             f. write_joined ( & self . substitution . as_slice ( Interner ) [ 1 .. ] ,  ", " ) ?; 
301+             f. write_joined ( proj_params ,  ", " ) ?; 
299302            write ! ( f,  ">" ) ?; 
300303        } 
301-         write ! ( f,  ">::{}" ,  f. db. type_alias_data( from_assoc_type_id( self . associated_ty_id) ) . name) ?; 
302304        Ok ( ( ) ) 
303305    } 
304306} 
@@ -641,9 +643,12 @@ impl HirDisplay for Ty {
641643                // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types) 
642644                if  f. display_target . is_test ( )  { 
643645                    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? 
644649                    if  parameters. len ( Interner )  > 0  { 
645650                        write ! ( f,  "<" ) ?; 
646-                         f. write_joined ( & * parameters. as_slice ( Interner ) ,  ", " ) ?; 
651+                         f. write_joined ( parameters. as_slice ( Interner ) ,  ", " ) ?; 
647652                        write ! ( f,  ">" ) ?; 
648653                    } 
649654                }  else  { 
@@ -972,9 +977,20 @@ fn write_bounds_like_dyn_trait(
972977                    angle_open = true ; 
973978                } 
974979                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,  " = " ) ?; 
978994                } 
979995                ty. hir_fmt ( f) ?; 
980996            } 
0 commit comments