Skip to content

Commit 39ecd05

Browse files
committed
embrace find_map and some whitespace changes
1 parent abe8959 commit 39ecd05

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/stacked_borrows.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,13 @@ impl<'tcx> Stack {
263263
.rev() // search top-to-bottom
264264
// Return permission of first item that grants access.
265265
// We require a permission with the right tag, ensuring U3 and F3.
266-
.filter_map(|(idx, item)|
266+
.find_map(|(idx, item)|
267267
if item.perm.grants(access) && tag == item.tag {
268268
Some((idx, item.perm))
269269
} else {
270270
None
271271
}
272272
)
273-
.next()
274273
}
275274

276275
/// Test if a memory `access` using pointer tagged `tag` is granted.
@@ -286,8 +285,8 @@ impl<'tcx> Stack {
286285
// Step 1: Find granting item.
287286
let (granting_idx, granting_perm) = self.find_granting(access, tag)
288287
.ok_or_else(|| InterpError::MachineError(format!(
289-
"no item granting {} access to tag {} found in borrow stack",
290-
access, tag,
288+
"no item granting {} access to tag {} found in borrow stack",
289+
access, tag,
291290
)))?;
292291

293292
// Step 2: Remove everything incompatible above them. Make sure we do not remove protected
@@ -313,9 +312,9 @@ impl<'tcx> Stack {
313312
if let Some(call) = item.protector {
314313
if global.is_active(call) {
315314
return err!(MachineError(format!(
316-
"not granting {} access to tag {} because incompatible item {} is protected",
317-
access, tag, item
318-
)));
315+
"not granting {} access to tag {} because incompatible item {} is protected",
316+
access, tag, item
317+
)));
319318
}
320319
}
321320
trace!("access: removing item {}", item);
@@ -337,8 +336,8 @@ impl<'tcx> Stack {
337336
// Step 1: Find granting item.
338337
self.find_granting(AccessKind::Write, tag)
339338
.ok_or_else(|| InterpError::MachineError(format!(
340-
"no item granting write access for deallocation to tag {} found in borrow stack",
341-
tag,
339+
"no item granting write access for deallocation to tag {} found in borrow stack",
340+
tag,
342341
)))?;
343342

344343
// We must make sure there are no protected items remaining on the stack.
@@ -386,10 +385,10 @@ impl<'tcx> Stack {
386385
) -> EvalResult<'tcx> {
387386
// Figure out which access `perm` corresponds to.
388387
let access = if new.perm.grants(AccessKind::Write) {
389-
AccessKind::Write
390-
} else {
391-
AccessKind::Read
392-
};
388+
AccessKind::Write
389+
} else {
390+
AccessKind::Read
391+
};
393392
// Now we figure out which item grants our parent (`derived_from`) this kind of access.
394393
// We use that to determine where to put the new item.
395394
let (derived_from_idx, _) = self.find_granting(access, derived_from)

0 commit comments

Comments
 (0)