@@ -991,37 +991,50 @@ impl Display for DisplayGenericContext<'_> {
991991}
992992
993993impl < ' db > Specialization < ' db > {
994- pub fn display ( & ' db self , db : & ' db dyn Db ) -> DisplaySpecialization < ' db > {
994+ pub fn display ( self , db : & ' db dyn Db ) -> DisplaySpecialization < ' db > {
995995 self . display_short ( db, TupleSpecialization :: No , DisplaySettings :: default ( ) )
996996 }
997997
998+ pub ( crate ) fn display_full ( self , db : & ' db dyn Db ) -> DisplaySpecialization < ' db > {
999+ DisplaySpecialization {
1000+ specialization : self ,
1001+ db,
1002+ tuple_specialization : TupleSpecialization :: No ,
1003+ settings : DisplaySettings :: default ( ) ,
1004+ full : true ,
1005+ }
1006+ }
1007+
9981008 /// Renders the specialization as it would appear in a subscript expression, e.g. `[int, str]`.
9991009 pub fn display_short (
1000- & ' db self ,
1010+ self ,
10011011 db : & ' db dyn Db ,
10021012 tuple_specialization : TupleSpecialization ,
10031013 settings : DisplaySettings < ' db > ,
10041014 ) -> DisplaySpecialization < ' db > {
10051015 DisplaySpecialization {
1006- types : self . types ( db ) ,
1016+ specialization : self ,
10071017 db,
10081018 tuple_specialization,
10091019 settings,
1020+ full : false ,
10101021 }
10111022 }
10121023}
10131024
10141025pub struct DisplaySpecialization < ' db > {
1015- types : & ' db [ Type < ' db > ] ,
1026+ specialization : Specialization < ' db > ,
10161027 db : & ' db dyn Db ,
10171028 tuple_specialization : TupleSpecialization ,
10181029 settings : DisplaySettings < ' db > ,
1030+ full : bool ,
10191031}
10201032
1021- impl Display for DisplaySpecialization < ' _ > {
1022- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1033+ impl DisplaySpecialization < ' _ > {
1034+ fn fmt_normal ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
10231035 f. write_char ( '[' ) ?;
1024- for ( idx, ty) in self . types . iter ( ) . enumerate ( ) {
1036+ let types = self . specialization . types ( self . db ) ;
1037+ for ( idx, ty) in types. iter ( ) . enumerate ( ) {
10251038 if idx > 0 {
10261039 f. write_str ( ", " ) ?;
10271040 }
@@ -1032,6 +1045,37 @@ impl Display for DisplaySpecialization<'_> {
10321045 }
10331046 f. write_char ( ']' )
10341047 }
1048+
1049+ fn fmt_full ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1050+ f. write_char ( '[' ) ?;
1051+ let variables = self
1052+ . specialization
1053+ . generic_context ( self . db )
1054+ . variables ( self . db ) ;
1055+ let types = self . specialization . types ( self . db ) ;
1056+ for ( idx, ( bound_typevar, ty) ) in variables. zip ( types) . enumerate ( ) {
1057+ if idx > 0 {
1058+ f. write_str ( ", " ) ?;
1059+ }
1060+ write ! (
1061+ f,
1062+ "{} = {}" ,
1063+ bound_typevar. identity( self . db) . display( self . db) ,
1064+ ty. display_with( self . db, self . settings. clone( ) ) ,
1065+ ) ?;
1066+ }
1067+ f. write_char ( ']' )
1068+ }
1069+ }
1070+
1071+ impl Display for DisplaySpecialization < ' _ > {
1072+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
1073+ if self . full {
1074+ self . fmt_full ( f)
1075+ } else {
1076+ self . fmt_normal ( f)
1077+ }
1078+ }
10351079}
10361080
10371081#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
0 commit comments