Skip to content

Commit 78210a5

Browse files
authored
Use drain instead of manually rolling it ourselves (#731)
Use `drain` instead of manually rolling it ourselves
2 parents 37b2eea + 3fde452 commit 78210a5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/stacked_borrows.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ impl<'tcx> Stack {
226226
)
227227
}
228228

229-
/// Find the first write-incompatible item above the given one --
229+
/// Find the first write-incompatible item above the given one --
230230
/// i.e, find the height to which the stack will be truncated when writing to `granting`.
231231
fn find_first_write_incompaible(&self, granting: usize) -> usize {
232232
let perm = self.borrows[granting].perm;
@@ -297,8 +297,7 @@ impl<'tcx> Stack {
297297
// Remove everything above the write-compatible items, like a proper stack. This makes sure read-only and unique
298298
// pointers become invalid on write accesses (ensures F2a, and ensures U2 for write accesses).
299299
let first_incompatible_idx = self.find_first_write_incompaible(granting_idx);
300-
while self.borrows.len() > first_incompatible_idx {
301-
let item = self.borrows.pop().unwrap();
300+
for item in self.borrows.drain(first_incompatible_idx..).rev() {
302301
trace!("access: popping item {}", item);
303302
Stack::check_protector(&item, Some(tag), global)?;
304303
}
@@ -340,8 +339,7 @@ impl<'tcx> Stack {
340339
)))?;
341340

342341
// Step 2: Remove all items. Also checks for protectors.
343-
while self.borrows.len() > 0 {
344-
let item = self.borrows.pop().unwrap();
342+
for item in self.borrows.drain(..).rev() {
345343
Stack::check_protector(&item, None, global)?;
346344
}
347345

0 commit comments

Comments
 (0)