Skip to content

Commit c430f98

Browse files
committed
Make commit and rollback_to methods take ownership of the snapshots.
Because they shouldn't be reused. This provides consistency with the `ena` crate.
1 parent d72cccc commit c430f98

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
790790

791791
self.projection_cache
792792
.borrow_mut()
793-
.commit(&projection_cache_snapshot);
793+
.commit(projection_cache_snapshot);
794794
self.type_variables.borrow_mut().commit(type_snapshot);
795795
self.int_unification_table.borrow_mut().commit(int_snapshot);
796796
self.float_unification_table

src/librustc/traits/project.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1652,15 +1652,15 @@ impl<'tcx> ProjectionCache<'tcx> {
16521652
}
16531653

16541654
pub fn rollback_to(&mut self, snapshot: ProjectionCacheSnapshot) {
1655-
self.map.rollback_to(&snapshot.snapshot);
1655+
self.map.rollback_to(snapshot.snapshot);
16561656
}
16571657

16581658
pub fn rollback_placeholder(&mut self, snapshot: &ProjectionCacheSnapshot) {
16591659
self.map.partial_rollback(&snapshot.snapshot, &|k| k.ty.has_re_skol());
16601660
}
16611661

1662-
pub fn commit(&mut self, snapshot: &ProjectionCacheSnapshot) {
1663-
self.map.commit(&snapshot.snapshot);
1662+
pub fn commit(&mut self, snapshot: ProjectionCacheSnapshot) {
1663+
self.map.commit(snapshot.snapshot);
16641664
}
16651665

16661666
/// Try to start normalize `key`; returns an error if

src/librustc_data_structures/snapshot_map/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ impl<K, V> SnapshotMap<K, V>
102102
});
103103
}
104104

105-
pub fn commit(&mut self, snapshot: &Snapshot) {
106-
self.assert_open_snapshot(snapshot);
105+
pub fn commit(&mut self, snapshot: Snapshot) {
106+
self.assert_open_snapshot(&snapshot);
107107
if snapshot.len == 0 {
108108
// The root snapshot.
109109
self.undo_log.clear();
@@ -134,8 +134,8 @@ impl<K, V> SnapshotMap<K, V>
134134
}
135135
}
136136

137-
pub fn rollback_to(&mut self, snapshot: &Snapshot) {
138-
self.assert_open_snapshot(snapshot);
137+
pub fn rollback_to(&mut self, snapshot: Snapshot) {
138+
self.assert_open_snapshot(&snapshot);
139139
while self.undo_log.len() > snapshot.len + 1 {
140140
let entry = self.undo_log.pop().unwrap();
141141
self.reverse(entry);

src/librustc_data_structures/snapshot_map/test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn basic() {
2020
map.insert(44, "fourty-four");
2121
assert_eq!(map[&44], "fourty-four");
2222
assert_eq!(map.get(&33), None);
23-
map.rollback_to(&snapshot);
23+
map.rollback_to(snapshot);
2424
assert_eq!(map[&22], "twenty-two");
2525
assert_eq!(map.get(&33), None);
2626
assert_eq!(map.get(&44), None);
@@ -33,7 +33,7 @@ fn out_of_order() {
3333
map.insert(22, "twenty-two");
3434
let snapshot1 = map.snapshot();
3535
let _snapshot2 = map.snapshot();
36-
map.rollback_to(&snapshot1);
36+
map.rollback_to(snapshot1);
3737
}
3838

3939
#[test]
@@ -43,8 +43,8 @@ fn nested_commit_then_rollback() {
4343
let snapshot1 = map.snapshot();
4444
let snapshot2 = map.snapshot();
4545
map.insert(22, "thirty-three");
46-
map.commit(&snapshot2);
46+
map.commit(snapshot2);
4747
assert_eq!(map[&22], "thirty-three");
48-
map.rollback_to(&snapshot1);
48+
map.rollback_to(snapshot1);
4949
assert_eq!(map[&22], "twenty-two");
5050
}

0 commit comments

Comments
 (0)