summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2018-06-11 19:11:48 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2018-06-19 19:38:37 +0200
commit6dfed7e813ae1d660ddaa4de778214b7906b87b3 (patch)
treedd69dc31b7816f836f9495512a7a76171873b4ac /src
parentbe645be6603b833a5b2540cb03e613e6718974aa (diff)
downloadrust-6dfed7e813ae1d660ddaa4de778214b7906b87b3.tar.gz
rust-6dfed7e813ae1d660ddaa4de778214b7906b87b3.zip
small refactoring: replaced mutable state with `return` statements in control flow.
As a drive-by, removed some dead-code.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/borrow_check/mod.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs
index a1c773637ec..03f0d4f3c2e 100644
--- a/src/librustc_mir/borrow_check/mod.rs
+++ b/src/librustc_mir/borrow_check/mod.rs
@@ -1702,7 +1702,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
             "check_access_permissions({:?}, {:?}, {:?})",
             place, kind, is_local_mutation_allowed
         );
-        let mut error_reported = false;
+
         match kind {
             Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Unique))
             | Reservation(WriteKind::MutableBorrow(borrow_kind @ BorrowKind::Mut { .. }))
@@ -1715,9 +1715,11 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                     BorrowKind::Shared => unreachable!(),
                 };
                 match self.is_mutable(place, is_local_mutation_allowed) {
-                    Ok(root_place) => self.add_used_mut(root_place, flow_state),
+                    Ok(root_place) => {
+                        self.add_used_mut(root_place, flow_state);
+                        return false;
+                    }
                     Err(place_err) => {
-                        error_reported = true;
                         let item_msg = self.get_default_err_msg(place);
                         let mut err = self.tcx
                             .cannot_borrow_path_as_mutable(span, &item_msg, Origin::Mir);
@@ -1731,15 +1733,17 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                         }
 
                         err.emit();
+                        return true;
                     }
                 }
             }
             Reservation(WriteKind::Mutate) | Write(WriteKind::Mutate) => {
                 match self.is_mutable(place, is_local_mutation_allowed) {
-                    Ok(root_place) => self.add_used_mut(root_place, flow_state),
+                    Ok(root_place) => {
+                        self.add_used_mut(root_place, flow_state);
+                        return false;
+                    }
                     Err(place_err) => {
-                        error_reported = true;
-
                         let err_info = if let Place::Projection(
                             box Projection {
                                 base: Place::Local(local),
@@ -1748,11 +1752,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                         ) = *place_err {
                             let locations = self.mir.find_assignments(local);
                             if locations.len() > 0 {
-                                let item_msg = if error_reported {
-                                    self.get_secondary_err_msg(&Place::Local(local))
-                                } else {
-                                    self.get_default_err_msg(place)
-                                };
+                                let item_msg = self.get_secondary_err_msg(&Place::Local(local));
                                 let sp = self.mir.source_info(locations[0]).span;
                                 let mut to_suggest_span = String::new();
                                 if let Ok(src) =
@@ -1797,6 +1797,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                             }
                             err.emit();
                         }
+
+                        return true;
                     }
                 }
             }
@@ -1815,15 +1817,20 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
                         ),
                     );
                 }
+                return false;
+            }
+            Activation(..) => {
+                // permission checks are done at Reservation point.
+                return false;
             }
-            Activation(..) => {} // permission checks are done at Reservation point.
             Read(ReadKind::Borrow(BorrowKind::Unique))
             | Read(ReadKind::Borrow(BorrowKind::Mut { .. }))
             | Read(ReadKind::Borrow(BorrowKind::Shared))
-            | Read(ReadKind::Copy) => {} // Access authorized
+            | Read(ReadKind::Copy) => {
+                // Access authorized
+                return false;
+            }
         }
-
-        error_reported
     }
 
     /// Adds the place into the used mutable variables set