From 39ecd05c46e96e606561d22163ea05be5b1fa6e2 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Wed, 17 Apr 2019 16:25:38 +0200 Subject: [PATCH] embrace find_map and some whitespace changes --- src/stacked_borrows.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/stacked_borrows.rs b/src/stacked_borrows.rs index dc2a78d2960..250def0c7ce 100644 --- a/src/stacked_borrows.rs +++ b/src/stacked_borrows.rs @@ -263,14 +263,13 @@ fn find_granting(&self, access: AccessKind, tag: Tag) -> Option<(usize, Permissi .rev() // search top-to-bottom // Return permission of first item that grants access. // We require a permission with the right tag, ensuring U3 and F3. - .filter_map(|(idx, item)| + .find_map(|(idx, item)| if item.perm.grants(access) && tag == item.tag { Some((idx, item.perm)) } else { None } ) - .next() } /// Test if a memory `access` using pointer tagged `tag` is granted. @@ -286,8 +285,8 @@ fn access( // Step 1: Find granting item. let (granting_idx, granting_perm) = self.find_granting(access, tag) .ok_or_else(|| InterpError::MachineError(format!( - "no item granting {} access to tag {} found in borrow stack", - access, tag, + "no item granting {} access to tag {} found in borrow stack", + access, tag, )))?; // Step 2: Remove everything incompatible above them. Make sure we do not remove protected @@ -313,9 +312,9 @@ fn access( if let Some(call) = item.protector { if global.is_active(call) { return err!(MachineError(format!( - "not granting {} access to tag {} because incompatible item {} is protected", - access, tag, item - ))); + "not granting {} access to tag {} because incompatible item {} is protected", + access, tag, item + ))); } } trace!("access: removing item {}", item); @@ -337,8 +336,8 @@ fn dealloc( // Step 1: Find granting item. self.find_granting(AccessKind::Write, tag) .ok_or_else(|| InterpError::MachineError(format!( - "no item granting write access for deallocation to tag {} found in borrow stack", - tag, + "no item granting write access for deallocation to tag {} found in borrow stack", + tag, )))?; // We must make sure there are no protected items remaining on the stack. @@ -386,10 +385,10 @@ fn reborrow( ) -> EvalResult<'tcx> { // Figure out which access `perm` corresponds to. let access = if new.perm.grants(AccessKind::Write) { - AccessKind::Write - } else { - AccessKind::Read - }; + AccessKind::Write + } else { + AccessKind::Read + }; // Now we figure out which item grants our parent (`derived_from`) this kind of access. // We use that to determine where to put the new item. let (derived_from_idx, _) = self.find_granting(access, derived_from) -- 2.44.0