Skip to content

Commit d5095f6

Browse files
committed
Fix mutability capture from place
1 parent 13a9c20 commit d5095f6

File tree

6 files changed

+307
-188
lines changed

6 files changed

+307
-188
lines changed

src/librustc/mir/tcx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl<'tcx> Place<'tcx> {
185185
// Base.[]
186186
// ^^^^ ^^-- no projection(empty)
187187
// |-- base_place
188-
pub fn final_projection<'cx, 'gcx>(
188+
pub fn split_projection<'cx, 'gcx>(
189189
&self,
190190
tcx: TyCtxt<'cx, 'gcx, 'tcx>,
191191
) -> (Place<'tcx>, Option<&'tcx PlaceElem<'tcx>>) {
@@ -216,7 +216,7 @@ impl<'tcx> Place<'tcx> {
216216
// Base.[] => Base.[]
217217
// ^^-- no projection
218218
pub fn projection_base<'cx, 'gcx>(&self, tcx: TyCtxt<'cx, 'gcx, 'tcx>) -> Place<'tcx> {
219-
match self.final_projection(tcx) {
219+
match self.split_projection(tcx) {
220220
(place, Some(_)) => place,
221221
(_, None) => self.clone(),
222222
}

src/librustc_mir/borrow_check/move_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
297297
// Ok to suggest a borrow, since the target can't be moved from
298298
// anyway.
299299
if let Ok(snippet) = self.tcx.sess.codemap().span_to_snippet(span) {
300-
if let (base_place, Some(proj)) = move_from.final_projection(self.tcx) {
300+
if let (base_place, Some(proj)) = move_from.split_projection(self.tcx) {
301301
if self.suitable_to_remove_deref(&base_place, proj, &snippet) {
302302
err.span_suggestion(
303303
span,

src/librustc_mir/borrow_check/mutability_errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
4141
let reason;
4242
let access_place_desc = self.describe_place(access_place);
4343

44-
if let (base_place, Some(projection)) = the_place_err.final_projection(self.tcx) {
44+
if let (base_place, Some(projection)) = the_place_err.split_projection(self.tcx) {
4545
match projection {
4646
ProjectionElem::Deref => {
4747
if base_place.base == PlaceBase::Local(Local::new(1))
@@ -188,7 +188,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
188188
}
189189
};
190190

191-
if let (base_place, Some(projection)) = the_place_err.final_projection(self.tcx) {
191+
if let (base_place, Some(projection)) = the_place_err.split_projection(self.tcx) {
192192
match projection {
193193
ProjectionElem::Deref => {
194194
if let PlaceBase::Local(local) = base_place.base {
@@ -360,7 +360,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
360360

361361
// Does this place refer to what the user sees as an upvar
362362
fn is_upvar(&self, place: &Place<'tcx>) -> bool {
363-
if let (base_place, Some(projection)) = place.final_projection(self.tcx) {
363+
if let (base_place, Some(projection)) = place.split_projection(self.tcx) {
364364
match projection {
365365
ProjectionElem::Field(_, _) => {
366366
let base_ty = base_place.ty(self.mir, self.tcx).to_ty(self.tcx);
@@ -370,7 +370,7 @@ impl<'a, 'gcx, 'tcx> MirBorrowckCtxt<'a, 'gcx, 'tcx> {
370370
if let (
371371
ref base_place,
372372
Some(ProjectionElem::Field(upvar_index, _)),
373-
) = base_place.final_projection(self.tcx) {
373+
) = base_place.split_projection(self.tcx) {
374374
let base_ty = base_place.ty(self.mir, self.tcx).to_ty(self.tcx);
375375
is_closure_or_generator(base_ty)
376376
&& self.mir.upvar_decls[upvar_index.index()].by_ref

0 commit comments

Comments
 (0)