Add is_ref_for_guard method

This commit is contained in:
Matthew Jasper 2019-05-04 22:26:59 +01:00
parent da9ebc828c
commit 5cfa70f760
4 changed files with 13 additions and 16 deletions

View File

@ -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]

View File

@ -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,

View File

@ -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
}

View File

@ -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