@@ -82,6 +82,20 @@ pub trait HirDisplay {
8282 } ;
8383 Ok ( result)
8484 }
85+
86+ /// Returns a String representation of `self` for test purposes
87+ fn display_test < ' a > ( & ' a self , db : & ' a dyn HirDatabase ) -> HirDisplayWrapper < ' a , Self >
88+ where
89+ Self : Sized ,
90+ {
91+ HirDisplayWrapper {
92+ db,
93+ t : self ,
94+ max_size : None ,
95+ omit_verbose_types : false ,
96+ display_target : DisplayTarget :: Test ,
97+ }
98+ }
8599}
86100
87101impl < ' a > HirFormatter < ' a > {
@@ -134,12 +148,17 @@ enum DisplayTarget {
134148 /// Display types for inserting them in source files.
135149 /// The generated code should compile, so paths need to be qualified.
136150 SourceCode { module_id : ModuleId } ,
151+ /// Only for test purpose to keep real types
152+ Test ,
137153}
138154
139155impl DisplayTarget {
140156 fn is_source_code ( & self ) -> bool {
141157 matches ! ( self , Self :: SourceCode { ..} )
142158 }
159+ fn is_test ( & self ) -> bool {
160+ matches ! ( self , Self :: Test )
161+ }
143162}
144163
145164#[ derive( Debug ) ]
@@ -313,14 +332,18 @@ impl HirDisplay for ApplicationTy {
313332 let ret_display = if f. omit_verbose_types ( ) {
314333 ret. display_truncated ( f. db , f. max_size )
315334 } else {
316- ret. display ( f. db )
335+ if f. display_target . is_test ( ) {
336+ ret. display_test ( f. db )
337+ } else {
338+ ret. display ( f. db )
339+ }
317340 } ;
318341 write ! ( f, " -> {}" , ret_display) ?;
319342 }
320343 }
321344 TypeCtor :: Adt ( def_id) => {
322345 match f. display_target {
323- DisplayTarget :: Diagnostics => {
346+ DisplayTarget :: Diagnostics | DisplayTarget :: Test => {
324347 let name = match def_id {
325348 AdtId :: StructId ( it) => f. db . struct_data ( it) . name . clone ( ) ,
326349 AdtId :: UnionId ( it) => f. db . union_data ( it) . name . clone ( ) ,
@@ -389,12 +412,23 @@ impl HirDisplay for ApplicationTy {
389412 _ => panic ! ( "not an associated type" ) ,
390413 } ;
391414 let trait_ = f. db . trait_data ( trait_) ;
392- let type_alias = f. db . type_alias_data ( type_alias) ;
393- write ! ( f, "{}::{}" , trait_. name, type_alias. name) ?;
394- if self . parameters . len ( ) > 0 {
395- write ! ( f, "<" ) ?;
396- f. write_joined ( & * self . parameters . 0 , ", " ) ?;
397- write ! ( f, ">" ) ?;
415+ let type_alias_data = f. db . type_alias_data ( type_alias) ;
416+
417+ // Use placeholder associated types when the target is test (https://rust-lang.github.io/chalk/book/clauses/type_equality.html#placeholder-associated-types)
418+ if f. display_target . is_test ( ) {
419+ write ! ( f, "{}::{}" , trait_. name, type_alias_data. name) ?;
420+ if self . parameters . len ( ) > 0 {
421+ write ! ( f, "<" ) ?;
422+ f. write_joined ( & * self . parameters . 0 , ", " ) ?;
423+ write ! ( f, ">" ) ?;
424+ }
425+ } else {
426+ let projection_ty = ProjectionTy {
427+ associated_ty : type_alias,
428+ parameters : self . parameters . clone ( ) ,
429+ } ;
430+
431+ projection_ty. hir_fmt ( f) ?;
398432 }
399433 }
400434 TypeCtor :: ForeignType ( type_alias) => {
@@ -442,7 +476,11 @@ impl HirDisplay for ApplicationTy {
442476 let ret_display = if f. omit_verbose_types ( ) {
443477 sig. ret ( ) . display_truncated ( f. db , f. max_size )
444478 } else {
445- sig. ret ( ) . display ( f. db )
479+ if f. display_target . is_test ( ) {
480+ sig. ret ( ) . display_test ( f. db )
481+ } else {
482+ sig. ret ( ) . display ( f. db )
483+ }
446484 } ;
447485 write ! ( f, " -> {}" , ret_display) ?;
448486 } else {
0 commit comments