@@ -35,7 +35,7 @@ use syntax_pos::{self, Span};
35
35
use traits:: { self , ObligationCause , PredicateObligations , TraitEngine } ;
36
36
use ty:: error:: { ExpectedFound , TypeError , UnconstrainedNumeric } ;
37
37
use ty:: fold:: TypeFoldable ;
38
- use ty:: relate:: RelateResult ;
38
+ use ty:: relate:: { RelateResult , TraitObjectMode } ;
39
39
use ty:: subst:: { Kind , Substs } ;
40
40
use ty:: { self , GenericParamDefKind , Ty , TyCtxt } ;
41
41
use ty:: { FloatVid , IntVid , TyVid } ;
@@ -182,6 +182,9 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
182
182
// This flag is true while there is an active snapshot.
183
183
in_snapshot : Cell < bool > ,
184
184
185
+ // The TraitObjectMode used here,
186
+ trait_object_mode : TraitObjectMode ,
187
+
185
188
// A set of constraints that regionck must validate. Each
186
189
// constraint has the form `T:'a`, meaning "some type `T` must
187
190
// outlive the lifetime 'a". These constraints derive from
@@ -472,6 +475,7 @@ pub struct InferCtxtBuilder<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
472
475
global_tcx : TyCtxt < ' a , ' gcx , ' gcx > ,
473
476
arena : SyncDroplessArena ,
474
477
fresh_tables : Option < RefCell < ty:: TypeckTables < ' tcx > > > ,
478
+ trait_object_mode : TraitObjectMode ,
475
479
}
476
480
477
481
impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' gcx > {
@@ -480,6 +484,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
480
484
global_tcx : self ,
481
485
arena : SyncDroplessArena :: default ( ) ,
482
486
fresh_tables : None ,
487
+ trait_object_mode : TraitObjectMode :: NoSquash ,
483
488
}
484
489
}
485
490
}
@@ -492,6 +497,12 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
492
497
self
493
498
}
494
499
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
+
495
506
/// Given a canonical value `C` as a starting point, create an
496
507
/// inference context that contains each of the bound values
497
508
/// within instantiated as a fresh variable. The `f` closure is
@@ -518,6 +529,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
518
529
pub fn enter < R > ( & ' tcx mut self , f : impl for < ' b > FnOnce ( InferCtxt < ' b , ' gcx , ' tcx > ) -> R ) -> R {
519
530
let InferCtxtBuilder {
520
531
global_tcx,
532
+ trait_object_mode,
521
533
ref arena,
522
534
ref fresh_tables,
523
535
} = * self ;
@@ -526,6 +538,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
526
538
f ( InferCtxt {
527
539
tcx,
528
540
in_progress_tables,
541
+ trait_object_mode,
529
542
projection_cache : Default :: default ( ) ,
530
543
type_variables : RefCell :: new ( type_variable:: TypeVariableTable :: new ( ) ) ,
531
544
int_unification_table : RefCell :: new ( ut:: UnificationTable :: new ( ) ) ,
@@ -607,6 +620,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
607
620
self . in_snapshot . get ( )
608
621
}
609
622
623
+ pub fn trait_object_mode ( & self ) -> TraitObjectMode {
624
+ self . trait_object_mode
625
+ }
626
+
610
627
pub fn freshen < T : TypeFoldable < ' tcx > > ( & self , t : T ) -> T {
611
628
t. fold_with ( & mut self . freshener ( ) )
612
629
}
0 commit comments