From 3c7d9ff90a06c44d31dad018ebb5e613b1c74033 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 13 Dec 2017 18:07:02 -0600 Subject: [PATCH] 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.) --- .../borrow_check/error_reporting.rs | 17 ++++------------- 1 file 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 dafd030a966a..31a94499fd0c 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..] {