@@ -163,6 +163,11 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
163163 // If the number of errors increases, that's also a sign (line
164164 // `tained_by_errors`) to avoid reporting certain kinds of errors.
165165 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 > ,
166171}
167172
168173/// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -476,7 +481,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> {
476481 normalize : false ,
477482 projection_mode : ProjectionMode :: AnyFinal ,
478483 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 ) ,
480486 }
481487 }
482488}
@@ -515,7 +521,8 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> {
515521 normalize : normalize,
516522 projection_mode : projection_mode,
517523 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 ) ,
519526 } ) )
520527 }
521528}
@@ -542,6 +549,7 @@ pub struct CombinedSnapshot {
542549 int_snapshot : unify:: Snapshot < ty:: IntVid > ,
543550 float_snapshot : unify:: Snapshot < ty:: FloatVid > ,
544551 region_vars_snapshot : RegionSnapshot ,
552+ obligations_in_snapshot : bool ,
545553}
546554
547555/// Helper trait for shortening the lifetimes inside a
@@ -809,11 +817,15 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
809817 }
810818
811819 fn start_snapshot ( & self ) -> CombinedSnapshot {
820+ let obligations_in_snapshot = self . obligations_in_snapshot . get ( ) ;
821+ self . obligations_in_snapshot . set ( false ) ;
822+
812823 CombinedSnapshot {
813824 type_snapshot : self . type_variables . borrow_mut ( ) . snapshot ( ) ,
814825 int_snapshot : self . int_unification_table . borrow_mut ( ) . snapshot ( ) ,
815826 float_snapshot : self . float_unification_table . borrow_mut ( ) . snapshot ( ) ,
816827 region_vars_snapshot : self . region_vars . start_snapshot ( ) ,
828+ obligations_in_snapshot : obligations_in_snapshot,
817829 }
818830 }
819831
@@ -822,7 +834,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
822834 let CombinedSnapshot { type_snapshot,
823835 int_snapshot,
824836 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) ;
826842
827843 self . type_variables
828844 . borrow_mut ( )
@@ -842,7 +858,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
842858 let CombinedSnapshot { type_snapshot,
843859 int_snapshot,
844860 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) ;
846865
847866 self . type_variables
848867 . borrow_mut ( )
@@ -904,12 +923,16 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
904923 let CombinedSnapshot { type_snapshot,
905924 int_snapshot,
906925 float_snapshot,
907- region_vars_snapshot } = self . start_snapshot ( ) ;
926+ region_vars_snapshot,
927+ obligations_in_snapshot } = self . start_snapshot ( ) ;
908928
909929 let r = self . commit_if_ok ( |_| f ( ) ) ;
910930
911931 debug ! ( "commit_regions_if_ok: rolling back everything but regions" ) ;
912932
933+ assert ! ( !self . obligations_in_snapshot. get( ) ) ;
934+ self . obligations_in_snapshot . set ( obligations_in_snapshot) ;
935+
913936 // Roll back any non-region bindings - they should be resolved
914937 // inside `f`, with, e.g. `resolve_type_vars_if_possible`.
915938 self . type_variables
0 commit comments