@@ -125,6 +125,13 @@ pub struct InferCtxt<'a, 'tcx> {
125
125
/// order, represented by its upper and lower bounds.
126
126
pub type_variables : RefCell < type_variable:: TypeVariableTable < ' tcx > > ,
127
127
128
+ /// If set, this flag causes us to skip the 'leak check' during
129
+ /// higher-ranked subtyping operations. This flag is a temporary one used
130
+ /// to manage the removal of the leak-check: for the time being, we still run the
131
+ /// leak-check, but we issue warnings. This flag can only be set to true
132
+ /// when entering a snapshot.
133
+ skip_leak_check : Cell < bool > ,
134
+
128
135
/// Map from const parameter variable to the kind of const it represents.
129
136
const_unification_table : RefCell < ut:: UnificationTable < ut:: InPlace < ty:: ConstVid < ' tcx > > > > ,
130
137
@@ -550,6 +557,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
550
557
tainted_by_errors_flag : Cell :: new ( false ) ,
551
558
err_count_on_creation : tcx. sess . err_count ( ) ,
552
559
in_snapshot : Cell :: new ( false ) ,
560
+ skip_leak_check : Cell :: new ( false ) ,
553
561
region_obligations : RefCell :: new ( vec ! [ ] ) ,
554
562
universe : Cell :: new ( ty:: UniverseIndex :: ROOT ) ,
555
563
} )
@@ -593,6 +601,7 @@ pub struct CombinedSnapshot<'a, 'tcx> {
593
601
region_obligations_snapshot : usize ,
594
602
universe : ty:: UniverseIndex ,
595
603
was_in_snapshot : bool ,
604
+ was_skip_leak_check : bool ,
596
605
_in_progress_tables : Option < Ref < ' a , ty:: TypeckTables < ' tcx > > > ,
597
606
}
598
607
@@ -720,6 +729,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
720
729
region_obligations_snapshot : self . region_obligations . borrow ( ) . len ( ) ,
721
730
universe : self . universe ( ) ,
722
731
was_in_snapshot : in_snapshot,
732
+ was_skip_leak_check : self . skip_leak_check . get ( ) ,
723
733
// Borrow tables "in progress" (i.e., during typeck)
724
734
// to ban writes from within a snapshot to them.
725
735
_in_progress_tables : self . in_progress_tables . map ( |tables| tables. borrow ( ) ) ,
@@ -738,11 +748,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
738
748
region_obligations_snapshot,
739
749
universe,
740
750
was_in_snapshot,
751
+ was_skip_leak_check,
741
752
_in_progress_tables,
742
753
} = snapshot;
743
754
744
755
self . in_snapshot . set ( was_in_snapshot) ;
745
756
self . universe . set ( universe) ;
757
+ self . skip_leak_check . set ( was_skip_leak_check) ;
746
758
747
759
self . projection_cache . borrow_mut ( ) . rollback_to ( projection_cache_snapshot) ;
748
760
self . type_variables . borrow_mut ( ) . rollback_to ( type_snapshot) ;
@@ -765,10 +777,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
765
777
region_obligations_snapshot : _,
766
778
universe : _,
767
779
was_in_snapshot,
780
+ was_skip_leak_check,
768
781
_in_progress_tables,
769
782
} = snapshot;
770
783
771
784
self . in_snapshot . set ( was_in_snapshot) ;
785
+ self . skip_leak_check . set ( was_skip_leak_check) ;
772
786
773
787
self . projection_cache . borrow_mut ( ) . commit ( projection_cache_snapshot) ;
774
788
self . type_variables . borrow_mut ( ) . commit ( type_snapshot) ;
@@ -822,6 +836,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
822
836
r
823
837
}
824
838
839
+ /// Execute `f` then unroll any bindings it creates.
840
+ pub fn skip_leak_check < R , F > ( & self , f : F ) -> R
841
+ where
842
+ F : FnOnce ( & CombinedSnapshot < ' a , ' tcx > ) -> R ,
843
+ {
844
+ debug ! ( "probe()" ) ;
845
+ let snapshot = self . start_snapshot ( ) ;
846
+ self . skip_leak_check . set ( true ) ;
847
+ let r = f ( & snapshot) ;
848
+ self . rollback_to ( "probe" , snapshot) ;
849
+ r
850
+ }
851
+
825
852
/// Scan the constraints produced since `snapshot` began and returns:
826
853
///
827
854
/// - `None` -- if none of them involve "region outlives" constraints
0 commit comments