@@ -163,6 +163,11 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
163
163
// If the number of errors increases, that's also a sign (line
164
164
// `tained_by_errors`) to avoid reporting certain kinds of errors.
165
165
err_count_on_creation : usize ,
166
+
167
+ // This flag is used for debugging, and is set to true if there are
168
+ // any obligations set during the current snapshot. In that case, the
169
+ // snapshot can't be rolled back.
170
+ pub obligations_in_snapshot : Cell < bool > ,
166
171
}
167
172
168
173
/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -476,7 +481,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
476
481
normalize : false ,
477
482
projection_mode : ProjectionMode :: AnyFinal ,
478
483
tainted_by_errors_flag : Cell :: new ( false ) ,
479
- err_count_on_creation : self . sess . err_count ( )
484
+ err_count_on_creation : self . sess . err_count ( ) ,
485
+ obligations_in_snapshot : Cell :: new ( false ) ,
480
486
}
481
487
}
482
488
}
@@ -515,7 +521,8 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
515
521
normalize : normalize,
516
522
projection_mode : projection_mode,
517
523
tainted_by_errors_flag : Cell :: new ( false ) ,
518
- err_count_on_creation : tcx. sess . err_count ( )
524
+ err_count_on_creation : tcx. sess . err_count ( ) ,
525
+ obligations_in_snapshot : Cell :: new ( false ) ,
519
526
} ) )
520
527
}
521
528
}
@@ -542,6 +549,7 @@ pub struct CombinedSnapshot {
542
549
int_snapshot : unify:: Snapshot < ty:: IntVid > ,
543
550
float_snapshot : unify:: Snapshot < ty:: FloatVid > ,
544
551
region_vars_snapshot : RegionSnapshot ,
552
+ obligations_in_snapshot : bool ,
545
553
}
546
554
547
555
/// Helper trait for shortening the lifetimes inside a
@@ -809,11 +817,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
809
817
}
810
818
811
819
fn start_snapshot ( & self ) -> CombinedSnapshot {
820
+ let obligations_in_snapshot = self . obligations_in_snapshot . get ( ) ;
821
+ self . obligations_in_snapshot . set ( false ) ;
822
+
812
823
CombinedSnapshot {
813
824
type_snapshot : self . type_variables . borrow_mut ( ) . snapshot ( ) ,
814
825
int_snapshot : self . int_unification_table . borrow_mut ( ) . snapshot ( ) ,
815
826
float_snapshot : self . float_unification_table . borrow_mut ( ) . snapshot ( ) ,
816
827
region_vars_snapshot : self . region_vars . start_snapshot ( ) ,
828
+ obligations_in_snapshot : obligations_in_snapshot,
817
829
}
818
830
}
819
831
@@ -822,7 +834,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
822
834
let CombinedSnapshot { type_snapshot,
823
835
int_snapshot,
824
836
float_snapshot,
825
- region_vars_snapshot } = snapshot;
837
+ region_vars_snapshot,
838
+ obligations_in_snapshot } = snapshot;
839
+
840
+ assert ! ( !self . obligations_in_snapshot. get( ) ) ;
841
+ self . obligations_in_snapshot . set ( obligations_in_snapshot) ;
826
842
827
843
self . type_variables
828
844
. borrow_mut ( )
@@ -842,7 +858,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
842
858
let CombinedSnapshot { type_snapshot,
843
859
int_snapshot,
844
860
float_snapshot,
845
- region_vars_snapshot } = snapshot;
861
+ region_vars_snapshot,
862
+ obligations_in_snapshot } = snapshot;
863
+
864
+ self . obligations_in_snapshot . set ( obligations_in_snapshot) ;
846
865
847
866
self . type_variables
848
867
. borrow_mut ( )
@@ -904,12 +923,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
904
923
let CombinedSnapshot { type_snapshot,
905
924
int_snapshot,
906
925
float_snapshot,
907
- region_vars_snapshot } = self . start_snapshot ( ) ;
926
+ region_vars_snapshot,
927
+ obligations_in_snapshot } = self . start_snapshot ( ) ;
908
928
909
929
let r = self . commit_if_ok ( |_| f ( ) ) ;
910
930
911
931
debug ! ( "commit_regions_if_ok: rolling back everything but regions" ) ;
912
932
933
+ assert ! ( !self . obligations_in_snapshot. get( ) ) ;
934
+ self . obligations_in_snapshot . set ( obligations_in_snapshot) ;
935
+
913
936
// Roll back any non-region bindings - they should be resolved
914
937
// inside `f`, with, e.g. `resolve_type_vars_if_possible`.
915
938
self . type_variables
0 commit comments