Improved is_upvar_field_projection - no longer need recurse parameter.

This commit is contained in:
David Wood 2018-07-21 14:16:25 +01:00
parent f71dbbb44f
commit ce4f446aa8
No known key found for this signature in database
GPG Key ID: 01760B4F9F53F154
4 changed files with 21 additions and 19 deletions

View File

@ -125,9 +125,18 @@ impl<'tcx> Place<'tcx> {
/// be `self` in the current MIR, because that is the only time we directly access the fields
/// of a closure type.
pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
tcx: &TyCtxt<'cx, 'gcx, 'tcx>,
recurse: bool) -> Option<Field> {
match *self {
tcx: &TyCtxt<'cx, 'gcx, 'tcx>) -> Option<Field> {
let place = if let Place::Projection(ref proj) = self {
if let ProjectionElem::Deref = proj.elem {
&proj.base
} else {
self
}
} else {
self
};
match place {
Place::Projection(ref proj) => match proj.elem {
ProjectionElem::Field(field, _ty) => {
let base_ty = proj.base.ty(mir, *tcx).to_ty(*tcx);
@ -138,13 +147,6 @@ impl<'tcx> Place<'tcx> {
None
}
},
ProjectionElem::Deref => {
if recurse {
proj.base.is_upvar_field_projection(mir, tcx, recurse)
} else {
None
}
},
_ => None,
},
_ => None,

View File

@ -726,8 +726,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Place::Projection(ref proj) => {
match proj.elem {
ProjectionElem::Deref => {
let upvar_field_projection = proj.base.is_upvar_field_projection(
self.mir, &self.tcx, false);
let upvar_field_projection = place.is_upvar_field_projection(
self.mir, &self.tcx);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
@ -788,7 +788,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
autoderef = true;
let upvar_field_projection = place.is_upvar_field_projection(
self.mir, &self.tcx, false);
self.mir, &self.tcx);
if let Some(field) = upvar_field_projection {
let var_index = field.index();
let name = self.mir.upvar_decls[var_index].debug_name.to_string();

View File

@ -1215,7 +1215,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
Operand::Move(ref place @ Place::Projection(_))
| Operand::Copy(ref place @ Place::Projection(_)) => {
if let Some(field) = place.is_upvar_field_projection(
self.mir, &self.tcx, false) {
self.mir, &self.tcx) {
self.used_mut_upvars.push(field);
}
}
@ -1804,7 +1804,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
place: place @ Place::Projection(_),
is_local_mutation_allowed: _,
} => {
if let Some(field) = place.is_upvar_field_projection(self.mir, &self.tcx, false) {
if let Some(field) = place.is_upvar_field_projection(self.mir, &self.tcx) {
self.used_mut_upvars.push(field);
}
}
@ -1867,8 +1867,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
// Mutably borrowed data is mutable, but only if we have a
// unique path to the `&mut`
hir::MutMutable => {
let mode = match proj.base.is_upvar_field_projection(
self.mir, &self.tcx, false)
let mode = match place.is_upvar_field_projection(
self.mir, &self.tcx)
{
Some(field)
if {
@ -1914,7 +1914,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
| ProjectionElem::Subslice { .. }
| ProjectionElem::Downcast(..) => {
let upvar_field_projection = place.is_upvar_field_projection(
self.mir, &self.tcx, false);
self.mir, &self.tcx);
if let Some(field) = upvar_field_projection {
let decl = &self.mir.upvar_decls[field.index()];
debug!(

View File

@ -175,7 +175,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
};
if initial_category == ConstraintCategory::Assignment
&& place.is_upvar_field_projection(mir, &infcx.tcx, true).is_some() {
&& place.is_upvar_field_projection(mir, &infcx.tcx).is_some() {
ConstraintCategory::AssignmentToUpvar
} else {
initial_category