diff options
| -rw-r--r-- | src/librustc/infer/region_constraints/mod.rs | 11 | ||||
| -rw-r--r-- | src/librustc_data_structures/snapshot_map/mod.rs | 10 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/librustc/infer/region_constraints/mod.rs b/src/librustc/infer/region_constraints/mod.rs index eb4c0d08f9f..231eff9ff9f 100644 --- a/src/librustc/infer/region_constraints/mod.rs +++ b/src/librustc/infer/region_constraints/mod.rs @@ -429,10 +429,14 @@ impl<'tcx> RegionConstraintCollector<'tcx> { } } - pub fn commit(&mut self, snapshot: RegionSnapshot) { - debug!("RegionConstraintCollector: commit({})", snapshot.length); + fn assert_open_snapshot(&self, snapshot: &RegionSnapshot) { assert!(self.undo_log.len() > snapshot.length); assert!(self.undo_log[snapshot.length] == OpenSnapshot); + } + + pub fn commit(&mut self, snapshot: RegionSnapshot) { + debug!("RegionConstraintCollector: commit({})", snapshot.length); + self.assert_open_snapshot(&snapshot); if snapshot.length == 0 { self.undo_log.clear(); @@ -444,8 +448,7 @@ impl<'tcx> RegionConstraintCollector<'tcx> { pub fn rollback_to(&mut self, snapshot: RegionSnapshot) { debug!("RegionConstraintCollector: rollback_to({:?})", snapshot); - assert!(self.undo_log.len() > snapshot.length); - assert!(self.undo_log[snapshot.length] == OpenSnapshot); + self.assert_open_snapshot(&snapshot); while self.undo_log.len() > snapshot.length + 1 { let undo_entry = self.undo_log.pop().unwrap(); self.rollback_undo_entry(undo_entry); diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index 8b761bdc8c6..a480499a30c 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -55,16 +55,20 @@ impl<K, V> SnapshotMap<K, V> self.undo_log.clear(); } + fn in_snapshot(&self) -> bool { + !self.undo_log.is_empty() + } + pub fn insert(&mut self, key: K, value: V) -> bool { match self.map.insert(key.clone(), value) { None => { - if !self.undo_log.is_empty() { + if self.in_snapshot() { self.undo_log.push(UndoLog::Inserted(key)); } true } Some(old_value) => { - if !self.undo_log.is_empty() { + if self.in_snapshot() { self.undo_log.push(UndoLog::Overwrite(key, old_value)); } false @@ -75,7 +79,7 @@ impl<K, V> SnapshotMap<K, V> pub fn remove(&mut self, key: K) -> bool { match self.map.remove(&key) { Some(old_value) => { - if !self.undo_log.is_empty() { + if self.in_snapshot() { self.undo_log.push(UndoLog::Overwrite(key, old_value)); } true |
