diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2019-05-04 22:26:59 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2019-06-03 12:59:08 +0100 |
| commit | 5cfa70f76088f973dd66f5bea9c6b0867378c16d (patch) | |
| tree | cf6aab1bdf2303501a45cd41e07ad5ed33bb4a6a | |
| parent | da9ebc828c982d2ed49396886da85011e1b0a6c0 (diff) | |
| download | rust-5cfa70f76088f973dd66f5bea9c6b0867378c16d.tar.gz rust-5cfa70f76088f973dd66f5bea9c6b0867378c16d.zip | |
Add `is_ref_for_guard` method
| -rw-r--r-- | src/librustc/mir/mod.rs | 10 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/error_reporting.rs | 4 | ||||
| -rw-r--r-- | src/librustc_mir/borrow_check/mutability_errors.rs | 7 | ||||
| -rw-r--r-- | src/librustc_mir/build/expr/as_rvalue.rs | 8 |
4 files changed, 13 insertions, 16 deletions
diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6213eda6514..c2b4a765c59 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -913,6 +913,16 @@ impl<'tcx> LocalDecl<'tcx> { } } + /// Returns `true` if this is a reference to a variable bound in a `match` + /// expression that is used to access said variable for the guard of the + /// match arm. + pub fn is_ref_for_guard(&self) -> bool { + match self.is_user_variable { + Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) => true, + _ => false, + } + } + /// Returns `true` is the local is from a compiler desugaring, e.g., /// `__next` from a `for` loop. #[inline] diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index 31af20fdb77..dea755411cc 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -180,9 +180,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { &including_downcast, )?; } else if let Place::Base(PlaceBase::Local(local)) = proj.base { - if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) = - self.mir.local_decls[local].is_user_variable - { + if self.mir.local_decls[local].is_ref_for_guard() { self.append_place_to_string( &proj.base, buf, diff --git a/src/librustc_mir/borrow_check/mutability_errors.rs b/src/librustc_mir/borrow_check/mutability_errors.rs index a292115707d..cbab84c2961 100644 --- a/src/librustc_mir/borrow_check/mutability_errors.rs +++ b/src/librustc_mir/borrow_check/mutability_errors.rs @@ -95,12 +95,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> { } } else if { if let Place::Base(PlaceBase::Local(local)) = *base { - if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) - = self.mir.local_decls[local].is_user_variable { - true - } else { - false - } + self.mir.local_decls[local].is_ref_for_guard() } else { false } diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 685db7713ca..87e2118094c 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -503,13 +503,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { elem: ProjectionElem::Deref, }) => { debug_assert!( - if let Some(ClearCrossCrate::Set(BindingForm::RefForGuard)) = - this.local_decls[local].is_user_variable - { - true - } else { - false - }, + this.local_decls[local].is_ref_for_guard(), "Unexpected capture place", ); this.local_decls[local].mutability |
