Skip to content

Commit ce4f446

Browse files
committed
Improved is_upvar_field_projection - no longer need recurse parameter.
1 parent f71dbbb commit ce4f446

File tree

4 files changed

+21
-19
lines changed

4 files changed

+21
-19
lines changed

src/librustc/mir/tcx.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,18 @@ impl<'tcx> Place<'tcx> {
125125
/// be `self` in the current MIR, because that is the only time we directly access the fields
126126
/// of a closure type.
127127
pub fn is_upvar_field_projection<'cx, 'gcx>(&self, mir: &'cx Mir<'tcx>,
128-
tcx: &TyCtxt<'cx, 'gcx, 'tcx>,
129-
recurse: bool) -> Option<Field> {
130-
match *self {
128+
tcx: &TyCtxt<'cx, 'gcx, 'tcx>) -> Option<Field> {
129+
let place = if let Place::Projection(ref proj) = self {
130+
if let ProjectionElem::Deref = proj.elem {
131+
&proj.base
132+
} else {
133+
self
134+
}
135+
} else {
136+
self
137+
};
138+
139+
match place {
131140
Place::Projection(ref proj) => match proj.elem {
132141
ProjectionElem::Field(field, _ty) => {
133142
let base_ty = proj.base.ty(mir, *tcx).to_ty(*tcx);
@@ -138,13 +147,6 @@ impl<'tcx> Place<'tcx> {
138147
None
139148
}
140149
},
141-
ProjectionElem::Deref => {
142-
if recurse {
143-
proj.base.is_upvar_field_projection(mir, tcx, recurse)
144-
} else {
145-
None
146-
}
147-
},
148150
_ => None,
149151
},
150152
_ => None,

src/librustc_mir/borrow_check/error_reporting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -726,8 +726,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
726726
Place::Projection(ref proj) => {
727727
match proj.elem {
728728
ProjectionElem::Deref => {
729-
let upvar_field_projection = proj.base.is_upvar_field_projection(
730-
self.mir, &self.tcx, false);
729+
let upvar_field_projection = place.is_upvar_field_projection(
730+
self.mir, &self.tcx);
731731
if let Some(field) = upvar_field_projection {
732732
let var_index = field.index();
733733
let name = self.mir.upvar_decls[var_index].debug_name.to_string();
@@ -788,7 +788,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
788788
autoderef = true;
789789

790790
let upvar_field_projection = place.is_upvar_field_projection(
791-
self.mir, &self.tcx, false);
791+
self.mir, &self.tcx);
792792
if let Some(field) = upvar_field_projection {
793793
let var_index = field.index();
794794
let name = self.mir.upvar_decls[var_index].debug_name.to_string();

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12151215
Operand::Move(ref place @ Place::Projection(_))
12161216
| Operand::Copy(ref place @ Place::Projection(_)) => {
12171217
if let Some(field) = place.is_upvar_field_projection(
1218-
self.mir, &self.tcx, false) {
1218+
self.mir, &self.tcx) {
12191219
self.used_mut_upvars.push(field);
12201220
}
12211221
}
@@ -1804,7 +1804,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18041804
place: place @ Place::Projection(_),
18051805
is_local_mutation_allowed: _,
18061806
} => {
1807-
if let Some(field) = place.is_upvar_field_projection(self.mir, &self.tcx, false) {
1807+
if let Some(field) = place.is_upvar_field_projection(self.mir, &self.tcx) {
18081808
self.used_mut_upvars.push(field);
18091809
}
18101810
}
@@ -1867,8 +1867,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18671867
// Mutably borrowed data is mutable, but only if we have a
18681868
// unique path to the `&mut`
18691869
hir::MutMutable => {
1870-
let mode = match proj.base.is_upvar_field_projection(
1871-
self.mir, &self.tcx, false)
1870+
let mode = match place.is_upvar_field_projection(
1871+
self.mir, &self.tcx)
18721872
{
18731873
Some(field)
18741874
if {
@@ -1914,7 +1914,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
19141914
| ProjectionElem::Subslice { .. }
19151915
| ProjectionElem::Downcast(..) => {
19161916
let upvar_field_projection = place.is_upvar_field_projection(
1917-
self.mir, &self.tcx, false);
1917+
self.mir, &self.tcx);
19181918
if let Some(field) = upvar_field_projection {
19191919
let decl = &self.mir.upvar_decls[field.index()];
19201920
debug!(

src/librustc_mir/borrow_check/nll/region_infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
175175
};
176176

177177
if initial_category == ConstraintCategory::Assignment
178-
&& place.is_upvar_field_projection(mir, &infcx.tcx, true).is_some() {
178+
&& place.is_upvar_field_projection(mir, &infcx.tcx).is_some() {
179179
ConstraintCategory::AssignmentToUpvar
180180
} else {
181181
initial_category

0 commit comments

Comments
 (0)