@@ -329,6 +329,14 @@ impl<'tcx> Generalizer<'_, 'tcx> {
329
329
}
330
330
}
331
331
332
+ /// Create a new type variable in the universe of the target when
333
+ /// generalizing an alias. This has to set `has_unconstrained_ty_var`
334
+ /// if we're currently in a bivariant context.
335
+ fn next_ty_var_for_alias ( & mut self ) -> Ty < ' tcx > {
336
+ self . has_unconstrained_ty_var |= self . ambient_variance == ty:: Bivariant ;
337
+ self . infcx . next_ty_var_in_universe ( self . span , self . for_universe )
338
+ }
339
+
332
340
/// An occurs check failure inside of an alias does not mean
333
341
/// that the types definitely don't unify. We may be able
334
342
/// to normalize the alias after all.
@@ -358,7 +366,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
358
366
//
359
367
// cc trait-system-refactor-initiative#110
360
368
if self . infcx . next_trait_solver ( ) && !alias. has_escaping_bound_vars ( ) && !self . in_alias {
361
- return Ok ( self . infcx . next_ty_var_in_universe ( self . span , self . for_universe ) ) ;
369
+ return Ok ( self . next_ty_var_for_alias ( ) ) ;
362
370
}
363
371
364
372
let is_nested_alias = mem:: replace ( & mut self . in_alias , true ) ;
@@ -378,7 +386,7 @@ impl<'tcx> Generalizer<'_, 'tcx> {
378
386
}
379
387
380
388
debug ! ( "generalization failure in alias" ) ;
381
- Ok ( self . infcx . next_ty_var_in_universe ( self . span , self . for_universe ) )
389
+ Ok ( self . next_ty_var_for_alias ( ) )
382
390
}
383
391
}
384
392
} ;
0 commit comments