about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-13 18:07:02 -0600
committerFelix S. Klock II <pnkfelix@pnkfx.org>2017-12-13 18:07:02 -0600
commit3c7d9ff90a06c44d31dad018ebb5e613b1c74033 (patch)
tree527535168df5d56f213d21adf58860ef1703e38e
parent5cae7a046922375352ca1ee33ae00df2123972ad (diff)
downloadrust-3c7d9ff90a06c44d31dad018ebb5e613b1c74033.tar.gz
rust-3c7d9ff90a06c44d31dad018ebb5e613b1c74033.zip
Address review comment: use `.get` instead of indexing to cope w/ terminators.
(Same net effect as code from before; just cleaner way to get there.)
-rw-r--r--src/librustc_mir/borrow_check/error_reporting.rs17
1 files changed, 4 insertions, 13 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs
index dafd030a966..31a94499fd0 100644
--- a/src/librustc_mir/borrow_check/error_reporting.rs
+++ b/src/librustc_mir/borrow_check/error_reporting.rs
@@ -11,7 +11,7 @@
 use syntax_pos::Span;
 use rustc::middle::region::ScopeTree;
 use rustc::mir::{BorrowKind, Field, Local, Location, Operand};
-use rustc::mir::{Place, ProjectionElem, Rvalue, StatementKind};
+use rustc::mir::{Place, ProjectionElem, Rvalue, Statement, StatementKind};
 use rustc::ty::{self, RegionKind};
 use rustc_data_structures::indexed_vec::Idx;
 
@@ -143,18 +143,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
         use rustc::hir::ExprClosure;
         use rustc::mir::AggregateKind;
 
-        if location.statement_index == self.mir[location.block].statements.len() {
-            // Code below hasn't been written in a manner to deal with
-            // a terminator location.
-            return None;
-        }
-
-        let local = if let StatementKind::Assign(Place::Local(local), _) =
-            self.mir[location.block].statements[location.statement_index].kind
-        {
-            local
-        } else {
-            return None;
+        let local = match self.mir[location.block].statements.get(location.statement_index) {
+            Some(&Statement { kind: StatementKind::Assign(Place::Local(local), _), .. }) => local,
+            _ => return None,
         };
 
         for stmt in &self.mir[location.block].statements[location.statement_index + 1..] {