@@ -68,6 +68,8 @@ fn compress<'tcx>(
6868fn encode_args < ' tcx > (
6969 tcx : TyCtxt < ' tcx > ,
7070 args : GenericArgsRef < ' tcx > ,
71+ for_def : DefId ,
72+ has_erased_self : bool ,
7173 dict : & mut FxHashMap < DictKey < ' tcx > , usize > ,
7274 options : EncodeTyOptions ,
7375) -> String {
@@ -76,7 +78,8 @@ fn encode_args<'tcx>(
7678 let args: Vec < GenericArg < ' _ > > = args. iter ( ) . collect ( ) ;
7779 if !args. is_empty ( ) {
7880 s. push ( 'I' ) ;
79- for arg in args {
81+ let def_generics = tcx. generics_of ( for_def) ;
82+ for ( n, arg) in args. iter ( ) . enumerate ( ) {
8083 match arg. unpack ( ) {
8184 GenericArgKind :: Lifetime ( region) => {
8285 s. push_str ( & encode_region ( region, dict) ) ;
@@ -85,7 +88,10 @@ fn encode_args<'tcx>(
8588 s. push_str ( & encode_ty ( tcx, ty, dict, options) ) ;
8689 }
8790 GenericArgKind :: Const ( c) => {
88- s. push_str ( & encode_const ( tcx, c, dict, options) ) ;
91+ let n = n + ( has_erased_self as usize ) ;
92+ let ct_ty =
93+ tcx. type_of ( def_generics. param_at ( n, tcx) . def_id ) . instantiate_identity ( ) ;
94+ s. push_str ( & encode_const ( tcx, c, ct_ty, dict, options) ) ;
8995 }
9096 }
9197 }
@@ -99,6 +105,7 @@ fn encode_args<'tcx>(
99105fn encode_const < ' tcx > (
100106 tcx : TyCtxt < ' tcx > ,
101107 c : Const < ' tcx > ,
108+ ct_ty : Ty < ' tcx > ,
102109 dict : & mut FxHashMap < DictKey < ' tcx > , usize > ,
103110 options : EncodeTyOptions ,
104111) -> String {
@@ -111,8 +118,7 @@ fn encode_const<'tcx>(
111118 // L<element-type>E as literal argument
112119
113120 // Element type
114- // THISPR
115- s. push_str ( & encode_ty ( tcx, todo ! ( ) , dict, options) ) ;
121+ s. push_str ( & encode_ty ( tcx, ct_ty, dict, options) ) ;
116122 }
117123
118124 // Literal arguments
@@ -232,15 +238,21 @@ fn encode_predicate<'tcx>(
232238 ty:: ExistentialPredicate :: Trait ( trait_ref) => {
233239 let name = encode_ty_name ( tcx, trait_ref. def_id ) ;
234240 let _ = write ! ( s, "u{}{}" , name. len( ) , & name) ;
235- s. push_str ( & encode_args ( tcx, trait_ref. args , dict, options) ) ;
241+ s. push_str ( & encode_args ( tcx, trait_ref. args , trait_ref . def_id , true , dict, options) ) ;
236242 }
237243 ty:: ExistentialPredicate :: Projection ( projection) => {
238244 let name = encode_ty_name ( tcx, projection. def_id ) ;
239245 let _ = write ! ( s, "u{}{}" , name. len( ) , & name) ;
240- s. push_str ( & encode_args ( tcx, projection. args , dict, options) ) ;
246+ s. push_str ( & encode_args ( tcx, projection. args , projection . def_id , true , dict, options) ) ;
241247 match projection. term . unpack ( ) {
242248 TermKind :: Ty ( ty) => s. push_str ( & encode_ty ( tcx, ty, dict, options) ) ,
243- TermKind :: Const ( c) => s. push_str ( & encode_const ( tcx, c, dict, options) ) ,
249+ TermKind :: Const ( c) => s. push_str ( & encode_const (
250+ tcx,
251+ c,
252+ tcx. type_of ( projection. def_id ) . instantiate ( tcx, projection. args ) ,
253+ dict,
254+ options,
255+ ) ) ,
244256 }
245257 }
246258 ty:: ExistentialPredicate :: AutoTrait ( def_id) => {
@@ -486,7 +498,7 @@ pub fn encode_ty<'tcx>(
486498 // <subst>, as vendor extended type.
487499 let name = encode_ty_name ( tcx, def_id) ;
488500 let _ = write ! ( s, "u{}{}" , name. len( ) , & name) ;
489- s. push_str ( & encode_args ( tcx, args, dict, options) ) ;
501+ s. push_str ( & encode_args ( tcx, args, def_id , false , dict, options) ) ;
490502 compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
491503 }
492504 typeid. push_str ( & s) ;
@@ -530,7 +542,7 @@ pub fn encode_ty<'tcx>(
530542 let mut s = String :: new ( ) ;
531543 let name = encode_ty_name ( tcx, * def_id) ;
532544 let _ = write ! ( s, "u{}{}" , name. len( ) , & name) ;
533- s. push_str ( & encode_args ( tcx, args, dict, options) ) ;
545+ s. push_str ( & encode_args ( tcx, args, * def_id , false , dict, options) ) ;
534546 compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
535547 typeid. push_str ( & s) ;
536548 }
@@ -542,7 +554,7 @@ pub fn encode_ty<'tcx>(
542554 let name = encode_ty_name ( tcx, * def_id) ;
543555 let _ = write ! ( s, "u{}{}" , name. len( ) , & name) ;
544556 let parent_args = tcx. mk_args ( args. as_coroutine_closure ( ) . parent_args ( ) ) ;
545- s. push_str ( & encode_args ( tcx, parent_args, dict, options) ) ;
557+ s. push_str ( & encode_args ( tcx, parent_args, * def_id , false , dict, options) ) ;
546558 compress ( dict, DictKey :: Ty ( ty, TyQ :: None ) , & mut s) ;
547559 typeid. push_str ( & s) ;
548560 }
@@ -557,6 +569,8 @@ pub fn encode_ty<'tcx>(
557569 s. push_str ( & encode_args (
558570 tcx,
559571 tcx. mk_args ( args. as_coroutine ( ) . parent_args ( ) ) ,
572+ * def_id,
573+ false ,
560574 dict,
561575 options,
562576 ) ) ;
0 commit comments