@@ -199,10 +199,8 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
199
199
// `tained_by_errors`) to avoid reporting certain kinds of errors.
200
200
err_count_on_creation : usize ,
201
201
202
- // This flag is used for debugging, and is set to true if there are
203
- // any obligations set during the current snapshot. In that case, the
204
- // snapshot can't be rolled back.
205
- pub obligations_in_snapshot : Cell < bool > ,
202
+ // This flag is true while there is an active snapshot.
203
+ in_snapshot : Cell < bool > ,
206
204
}
207
205
208
206
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -507,7 +505,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
507
505
projection_mode : Reveal :: UserFacing ,
508
506
tainted_by_errors_flag : Cell :: new ( false ) ,
509
507
err_count_on_creation : self . sess . err_count ( ) ,
510
- obligations_in_snapshot : Cell :: new ( false ) ,
508
+ in_snapshot : Cell :: new ( false ) ,
511
509
}
512
510
}
513
511
}
@@ -545,7 +543,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
545
543
projection_mode : projection_mode,
546
544
tainted_by_errors_flag : Cell :: new ( false ) ,
547
545
err_count_on_creation : tcx. sess . err_count ( ) ,
548
- obligations_in_snapshot : Cell :: new ( false ) ,
546
+ in_snapshot : Cell :: new ( false ) ,
549
547
} ) )
550
548
}
551
549
}
@@ -573,7 +571,7 @@ pub struct CombinedSnapshot {
573
571
int_snapshot : unify:: Snapshot < ty:: IntVid > ,
574
572
float_snapshot : unify:: Snapshot < ty:: FloatVid > ,
575
573
region_vars_snapshot : RegionSnapshot ,
576
- obligations_in_snapshot : bool ,
574
+ was_in_snapshot : bool ,
577
575
}
578
576
579
577
/// Helper trait for shortening the lifetimes inside a
@@ -734,6 +732,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
734
732
self . projection_mode
735
733
}
736
734
735
+ pub fn is_in_snapshot ( & self ) -> bool {
736
+ self . in_snapshot . get ( )
737
+ }
738
+
737
739
pub fn freshen < T : TypeFoldable < ' tcx > > ( & self , t : T ) -> T {
738
740
t. fold_with ( & mut self . freshener ( ) )
739
741
}
@@ -861,46 +863,45 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
861
863
result. map ( move |t| InferOk { value : t, obligations : fields. obligations } )
862
864
}
863
865
864
- // Clear the "obligations in snapshot" flag, invoke the closure,
866
+ // Clear the "currently in a snapshot" flag, invoke the closure,
865
867
// then restore the flag to its original value. This flag is a
866
868
// debugging measure designed to detect cases where we start a
867
- // snapshot, create type variables, register obligations involving
868
- // those type variables in the fulfillment cx, and then have to
869
- // unroll the snapshot, leaving "dangling type variables" behind.
870
- // In such cases, the flag will be set by the fulfillment cx, and
871
- // an assertion will fail when rolling the snapshot back. Very
872
- // useful, much better than grovelling through megabytes of
873
- // RUST_LOG output.
869
+ // snapshot, create type variables, and register obligations
870
+ // which may involve those type variables in the fulfillment cx,
871
+ // potentially leaving "dangling type variables" behind.
872
+ // In such cases, an assertion will fail when attempting to
873
+ // register obligations, within a snapshot. Very useful, much
874
+ // better than grovelling through megabytes of RUST_LOG output.
874
875
//
875
- // HOWEVER, in some cases the flag is wrong . In particular, we
876
+ // HOWEVER, in some cases the flag is unhelpful . In particular, we
876
877
// sometimes create a "mini-fulfilment-cx" in which we enroll
877
878
// obligations. As long as this fulfillment cx is fully drained
878
879
// before we return, this is not a problem, as there won't be any
879
880
// escaping obligations in the main cx. In those cases, you can
880
881
// use this function.
881
- pub fn save_and_restore_obligations_in_snapshot_flag < F , R > ( & self , func : F ) -> R
882
+ pub fn save_and_restore_in_snapshot_flag < F , R > ( & self , func : F ) -> R
882
883
where F : FnOnce ( & Self ) -> R
883
884
{
884
- let flag = self . obligations_in_snapshot . get ( ) ;
885
- self . obligations_in_snapshot . set ( false ) ;
885
+ let flag = self . in_snapshot . get ( ) ;
886
+ self . in_snapshot . set ( false ) ;
886
887
let result = func ( self ) ;
887
- self . obligations_in_snapshot . set ( flag) ;
888
+ self . in_snapshot . set ( flag) ;
888
889
result
889
890
}
890
891
891
892
fn start_snapshot ( & self ) -> CombinedSnapshot {
892
893
debug ! ( "start_snapshot()" ) ;
893
894
894
- let obligations_in_snapshot = self . obligations_in_snapshot . get ( ) ;
895
- self . obligations_in_snapshot . set ( false ) ;
895
+ let in_snapshot = self . in_snapshot . get ( ) ;
896
+ self . in_snapshot . set ( true ) ;
896
897
897
898
CombinedSnapshot {
898
899
projection_cache_snapshot : self . projection_cache . borrow_mut ( ) . snapshot ( ) ,
899
900
type_snapshot : self . type_variables . borrow_mut ( ) . snapshot ( ) ,
900
901
int_snapshot : self . int_unification_table . borrow_mut ( ) . snapshot ( ) ,
901
902
float_snapshot : self . float_unification_table . borrow_mut ( ) . snapshot ( ) ,
902
903
region_vars_snapshot : self . region_vars . start_snapshot ( ) ,
903
- obligations_in_snapshot : obligations_in_snapshot ,
904
+ was_in_snapshot : in_snapshot ,
904
905
}
905
906
}
906
907
@@ -911,10 +912,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
911
912
int_snapshot,
912
913
float_snapshot,
913
914
region_vars_snapshot,
914
- obligations_in_snapshot } = snapshot;
915
+ was_in_snapshot } = snapshot;
915
916
916
- assert ! ( !self . obligations_in_snapshot. get( ) ) ;
917
- self . obligations_in_snapshot . set ( obligations_in_snapshot) ;
917
+ self . in_snapshot . set ( was_in_snapshot) ;
918
918
919
919
self . projection_cache
920
920
. borrow_mut ( )
@@ -939,9 +939,9 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
939
939
int_snapshot,
940
940
float_snapshot,
941
941
region_vars_snapshot,
942
- obligations_in_snapshot } = snapshot;
942
+ was_in_snapshot } = snapshot;
943
943
944
- self . obligations_in_snapshot . set ( obligations_in_snapshot ) ;
944
+ self . in_snapshot . set ( was_in_snapshot ) ;
945
945
946
946
self . projection_cache
947
947
. borrow_mut ( )
0 commit comments