diff options
| -rw-r--r-- | src/librustc_infer/infer/mod.rs | 33 | ||||
| -rw-r--r-- | src/librustc_infer/infer/outlives/obligations.rs | 9 | ||||
| -rw-r--r-- | src/librustc_trait_selection/traits/auto_trait.rs | 2 |
3 files changed, 23 insertions, 21 deletions
diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index df8119bfa54..e594bf450dd 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -196,7 +196,7 @@ pub struct InferCtxtInner<'tcx> { /// for each body-id in this map, which will process the /// obligations within. This is expected to be done 'late enough' /// that all type inference variables have been bound and so forth. - pub region_obligations: Vec<(hir::HirId, RegionObligation<'tcx>)>, + region_obligations: Vec<(hir::HirId, RegionObligation<'tcx>)>, } impl<'tcx> InferCtxtInner<'tcx> { @@ -213,6 +213,10 @@ impl<'tcx> InferCtxtInner<'tcx> { } } + pub fn region_obligations(&self) -> &[(hir::HirId, RegionObligation<'tcx>)] { + &self.region_obligations + } + pub(crate) fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> { self.projection_cache.with_log(&mut self.undo_log) } @@ -270,6 +274,7 @@ pub(crate) enum UndoLog<'tcx> { RegionConstraintCollector(region_constraints::UndoLog<'tcx>), RegionUnificationTable(sv::UndoLog<ut::Delegate<ty::RegionVid>>), ProjectionCache(traits::UndoLog<'tcx>), + PushRegionObligation, } impl<'tcx> From<region_constraints::UndoLog<'tcx>> for UndoLog<'tcx> { @@ -348,6 +353,7 @@ struct RollbackView<'tcx, 'a> { float_unification_table: &'a mut ut::UnificationStorage<ty::FloatVid>, region_constraints: &'a mut RegionConstraintStorage<'tcx>, projection_cache: &'a mut traits::ProjectionCacheStorage<'tcx>, + region_obligations: &'a mut Vec<(hir::HirId, RegionObligation<'tcx>)>, } impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> { @@ -362,6 +368,9 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> { self.region_constraints.unification_table.reverse(undo) } UndoLog::ProjectionCache(undo) => self.projection_cache.reverse(undo), + UndoLog::PushRegionObligation => { + self.region_obligations.pop(); + } } } } @@ -915,7 +924,6 @@ pub struct FullSnapshot<'a, 'tcx> { #[must_use = "once you start a snapshot, you should always consume it"] pub struct CombinedSnapshot<'a, 'tcx> { undo_snapshot: Snapshot<'tcx>, - region_obligations_snapshot: usize, universe: ty::UniverseIndex, was_in_snapshot: bool, _in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>, @@ -1052,7 +1060,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let undo_snapshot = Snapshot { undo_len: inner.undo_log.logs.len(), _marker: PhantomData }; CombinedSnapshot { undo_snapshot, - region_obligations_snapshot: inner.region_obligations.len(), universe: self.universe(), was_in_snapshot: in_snapshot, // Borrow tables "in progress" (i.e., during typeck) @@ -1063,13 +1070,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'a, 'tcx>) { debug!("rollback_to(cause={})", cause); - let CombinedSnapshot { - undo_snapshot, - region_obligations_snapshot, - universe, - was_in_snapshot, - _in_progress_tables, - } = snapshot; + let CombinedSnapshot { undo_snapshot, universe, was_in_snapshot, _in_progress_tables } = + snapshot; self.in_snapshot.set(was_in_snapshot); self.universe.set(universe); @@ -1093,21 +1095,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { float_unification_table, region_constraints: region_constraints.as_mut().unwrap(), projection_cache, + region_obligations, }, undo_snapshot, ); - region_obligations.truncate(region_obligations_snapshot); } fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) { debug!("commit_from()"); - let CombinedSnapshot { - undo_snapshot, - region_obligations_snapshot: _, - universe: _, - was_in_snapshot, - _in_progress_tables, - } = snapshot; + let CombinedSnapshot { undo_snapshot, universe: _, was_in_snapshot, _in_progress_tables } = + snapshot; self.in_snapshot.set(was_in_snapshot); diff --git a/src/librustc_infer/infer/outlives/obligations.rs b/src/librustc_infer/infer/outlives/obligations.rs index c904926e9d9..f068afc8dff 100644 --- a/src/librustc_infer/infer/outlives/obligations.rs +++ b/src/librustc_infer/infer/outlives/obligations.rs @@ -61,7 +61,10 @@ use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::outlives::verify::VerifyBoundCx; -use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound}; +use crate::infer::{ + self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound, +}; +use crate::rustc_data_structures::undo_log::UndoLogs; use crate::traits::ObligationCause; use rustc_middle::ty::outlives::Component; use rustc_middle::ty::subst::GenericArgKind; @@ -84,7 +87,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> { ) { debug!("register_region_obligation(body_id={:?}, obligation={:?})", body_id, obligation); - self.inner.borrow_mut().region_obligations.push((body_id, obligation)); + let mut inner = self.inner.borrow_mut(); + inner.undo_log.push(UndoLog::PushRegionObligation); + inner.region_obligations.push((body_id, obligation)); } pub fn register_region_obligation_with_cause( diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs index 6326a87c5ed..e19ddcd9e5e 100644 --- a/src/librustc_trait_selection/traits/auto_trait.rs +++ b/src/librustc_trait_selection/traits/auto_trait.rs @@ -195,7 +195,7 @@ impl<'tcx> AutoTraitFinder<'tcx> { let body_id_map: FxHashMap<_, _> = infcx .inner .borrow() - .region_obligations + .region_obligations() .iter() .map(|&(id, _)| (id, vec![])) .collect(); |
