@@ -35,7 +35,7 @@ use syntax_pos::{self, Span};
3535use traits:: { self , ObligationCause , PredicateObligations , TraitEngine } ;
3636use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
3737use ty:: fold:: TypeFoldable ;
38- use ty:: relate:: RelateResult ;
38+ use ty:: relate:: { RelateResult , TraitObjectMode } ;
3939use ty:: subst:: { Kind , Substs } ;
4040use ty:: { self , GenericParamDefKind , Ty , TyCtxt } ;
4141use ty:: { FloatVid , IntVid , TyVid } ;
@@ -182,6 +182,9 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
182182 // This flag is true while there is an active snapshot.
183183 in_snapshot : Cell < bool > ,
184184
185+ // The TraitObjectMode used here,
186+ trait_object_mode : TraitObjectMode ,
187+
185188 // A set of constraints that regionck must validate. Each
186189 // constraint has the form `T:'a`, meaning "some type `T` must
187190 // outlive the lifetime 'a". These constraints derive from
@@ -472,6 +475,7 @@ pub struct InferCtxtBuilder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
472475 global_tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
473476 arena : SyncDroplessArena ,
474477 fresh_tables : Option < RefCell < ty:: TypeckTables < ' tcx > > > ,
478+ trait_object_mode : TraitObjectMode ,
475479}
476480
477481impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' gcx > {
@@ -480,6 +484,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
480484 global_tcx : self ,
481485 arena : SyncDroplessArena :: default ( ) ,
482486 fresh_tables : None ,
487+ trait_object_mode : TraitObjectMode :: NoSquash ,
483488 }
484489 }
485490}
@@ -492,6 +497,12 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
492497 self
493498 }
494499
500+ pub fn with_trait_object_mode ( mut self , mode : TraitObjectMode ) -> Self {
501+ debug ! ( "with_trait_object_mode: setting mode to {:?}" , mode) ;
502+ self . trait_object_mode = mode;
503+ self
504+ }
505+
495506 /// Given a canonical value `C` as a starting point, create an
496507 /// inference context that contains each of the bound values
497508 /// within instantiated as a fresh variable. The `f` closure is
@@ -518,6 +529,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
518529 pub fn enter < R > ( & ' tcx mut self , f : impl for < ' b > FnOnce ( InferCtxt < ' b , ' gcx , ' tcx > ) -> R ) -> R {
519530 let InferCtxtBuilder {
520531 global_tcx,
532+ trait_object_mode,
521533 ref arena,
522534 ref fresh_tables,
523535 } = * self ;
@@ -526,6 +538,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
526538 f ( InferCtxt {
527539 tcx,
528540 in_progress_tables,
541+ trait_object_mode,
529542 projection_cache : Default :: default ( ) ,
530543 type_variables : RefCell :: new ( type_variable:: TypeVariableTable :: new ( ) ) ,
531544 int_unification_table : RefCell :: new ( ut:: UnificationTable :: new ( ) ) ,
@@ -607,6 +620,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
607620 self . in_snapshot . get ( )
608621 }
609622
623+ pub fn trait_object_mode ( & self ) -> TraitObjectMode {
624+ self . trait_object_mode
625+ }
626+
610627 pub fn freshen < T : TypeFoldable < ' tcx > > ( & self , t : T ) -> T {
611628 t. fold_with ( & mut self . freshener ( ) )
612629 }
0 commit comments