diff options
| author | Remy Rakic <remy.rakic@gmail.com> | 2018-09-14 22:22:02 +0200 |
|---|---|---|
| committer | Remy Rakic <remy.rakic@gmail.com> | 2018-09-18 14:36:37 +0200 |
| commit | 75b94e24bf21304a3d2a4f5aac39f893b4ac4245 (patch) | |
| tree | 8261cefa3596d1d23e8092209e370191c0a061e5 | |
| parent | ae6479c13bd3fdb17ed055b88f4ca166dabb4e9f (diff) | |
| download | rust-75b94e24bf21304a3d2a4f5aac39f893b4ac4245.tar.gz rust-75b94e24bf21304a3d2a4f5aac39f893b4ac4245.zip | |
Create a helper function to retrieve the FakeReadClause at a location
| -rw-r--r-- | src/librustc_mir/borrow_check/error_reporting.rs | 17 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs | 26 |
2 files changed, 20 insertions, 23 deletions
diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 4671332f282..de2c2164a1f 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -12,7 +12,7 @@ use borrow_check::WriteKind; use rustc::middle::region::ScopeTree; use rustc::mir::VarBindingForm; use rustc::mir::{BindingForm, BorrowKind, ClearCrossCrate, Field, Local}; -use rustc::mir::{LocalDecl, LocalKind, Location, Operand, Place}; +use rustc::mir::{FakeReadCause, LocalDecl, LocalKind, Location, Operand, Place}; use rustc::mir::{ProjectionElem, Rvalue, Statement, StatementKind}; use rustc::ty; use rustc_data_structures::fx::FxHashSet; @@ -989,6 +989,21 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { false } } + + /// Returns the `FakeReadCause` at this location if it is a `FakeRead` statement. + pub(super) fn retrieve_fake_read_cause_for_location( + &self, + location: &Location, + ) -> Option<FakeReadCause> { + let stmt = self.mir.basic_blocks()[location.block] + .statements + .get(location.statement_index)?; + if let StatementKind::FakeRead(cause, _) = stmt.kind { + Some(cause) + } else { + None + } + } } // The span(s) associated to a use of a place. diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index a62e608a875..c094350757e 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -11,7 +11,7 @@ use borrow_check::borrow_set::BorrowData; use borrow_check::nll::region_infer::Cause; use borrow_check::{Context, MirBorrowckCtxt, WriteKind}; -use rustc::mir::{FakeReadCause, Local, Location, Place, StatementKind, TerminatorKind}; +use rustc::mir::{FakeReadCause, Local, Location, Place, TerminatorKind}; use rustc_errors::DiagnosticBuilder; use rustc::ty::Region; @@ -145,27 +145,9 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { // Check if the location represents a `FakeRead`, and adapt the error // message to the `FakeReadCause` it is from: in particular, // the ones inserted in optimized `let var = <expr>` patterns. - let is_fake_read_for_let = match self.mir.basic_blocks()[location.block] - .statements - .get(location.statement_index) - { - None => false, - Some(stmt) => { - if let StatementKind::FakeRead(ref cause, _) = stmt.kind { - match cause { - FakeReadCause::ForLet => true, - _ => false, - } - } else { - false - } - } - }; - - if is_fake_read_for_let { - "borrow later stored here" - } else { - "borrow later used here" + match self.retrieve_fake_read_cause_for_location(&location) { + Some(FakeReadCause::ForLet) => "borrow later stored here", + _ => "borrow later used here" } } }; |
