@@ -259,11 +259,11 @@ impl<'tcx> InferCtxt<'tcx> {
259
259
structurally_relate_aliases,
260
260
root_vid,
261
261
for_universe,
262
- ambient_variance,
263
262
root_term : source_term. into ( ) ,
263
+ ambient_variance,
264
264
in_alias : false ,
265
- has_unconstrained_ty_var : false ,
266
265
cache : Default :: default ( ) ,
266
+ has_unconstrained_ty_var : false ,
267
267
} ;
268
268
269
269
let value_may_be_infer = generalizer. relate ( source_term, source_term) ?;
@@ -304,14 +304,12 @@ struct Generalizer<'me, 'tcx> {
304
304
/// we reject the relation.
305
305
for_universe : ty:: UniverseIndex ,
306
306
307
- /// After we generalize this type, we are going to relate it to
308
- /// some other type. What will be the variance at this point?
309
- ambient_variance : ty:: Variance ,
310
-
311
307
/// The root term (const or type) we're generalizing. Used for cycle errors.
312
308
root_term : Term < ' tcx > ,
313
309
314
- cache : SsoHashMap < Ty < ' tcx > , Ty < ' tcx > > ,
310
+ /// After we generalize this type, we are going to relate it to
311
+ /// some other type. What will be the variance at this point?
312
+ ambient_variance : ty:: Variance ,
315
313
316
314
/// This is set once we're generalizing the arguments of an alias.
317
315
///
@@ -320,6 +318,8 @@ struct Generalizer<'me, 'tcx> {
320
318
/// hold by either normalizing the outer or the inner associated type.
321
319
in_alias : bool ,
322
320
321
+ cache : SsoHashMap < ( Ty < ' tcx > , ty:: Variance , bool ) , Ty < ' tcx > > ,
322
+
323
323
/// See the field `has_unconstrained_ty_var` in `Generalization`.
324
324
has_unconstrained_ty_var : bool ,
325
325
}
@@ -451,7 +451,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
451
451
fn tys ( & mut self , t : Ty < ' tcx > , t2 : Ty < ' tcx > ) -> RelateResult < ' tcx , Ty < ' tcx > > {
452
452
assert_eq ! ( t, t2) ; // we are misusing TypeRelation here; both LHS and RHS ought to be ==
453
453
454
- if let Some ( & result) = self . cache . get ( & t ) {
454
+ if let Some ( & result) = self . cache . get ( & ( t , self . ambient_variance , self . in_alias ) ) {
455
455
return Ok ( result) ;
456
456
}
457
457
@@ -557,7 +557,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
557
557
_ => relate:: structurally_relate_tys ( self , t, t) ,
558
558
} ?;
559
559
560
- self . cache . insert ( t , g) ;
560
+ self . cache . insert ( ( t , self . ambient_variance , self . in_alias ) , g) ;
561
561
Ok ( g)
562
562
}
563
563
0 commit comments