From a0f4914ccbb6915a150a5e57a8dab12d5afc4d8c Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Fri, 26 Apr 2019 22:18:59 +0200 Subject: [PATCH 1/3] This continue is not needed --- src/librustc_mir/borrow_check/mod.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 1d65a018dd62d..fc1f5eb5d5a7a 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -1831,7 +1831,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { } place = base; - continue; } } } From 9f7b953a7e691139ada3f390cd6f8ee9e5279642 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 2 May 2019 01:07:28 +0200 Subject: [PATCH 2/3] Remove root_local fn in favor of base_local --- src/librustc_mir/borrow_check/borrow_set.rs | 2 +- src/librustc_mir/borrow_check/place_ext.rs | 17 +---------------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 56dacf20edcb8..5ced497baa1fd 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -210,7 +210,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> { self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx); - if let Some(local) = borrowed_place.root_local() { + if let Some(local) = borrowed_place.base_local() { self.local_map.entry(local).or_default().insert(idx); } } diff --git a/src/librustc_mir/borrow_check/place_ext.rs b/src/librustc_mir/borrow_check/place_ext.rs index 913884a821837..cf9a6165d71a2 100644 --- a/src/librustc_mir/borrow_check/place_ext.rs +++ b/src/librustc_mir/borrow_check/place_ext.rs @@ -1,6 +1,6 @@ use rustc::hir; use rustc::mir::ProjectionElem; -use rustc::mir::{Local, Mir, Place, PlaceBase, Mutability, Static, StaticKind}; +use rustc::mir::{Mir, Place, PlaceBase, Mutability, Static, StaticKind}; use rustc::ty::{self, TyCtxt}; use crate::borrow_check::borrow_set::LocalsStateAtExit; @@ -16,10 +16,6 @@ crate trait PlaceExt<'tcx> { mir: &Mir<'tcx>, locals_state_at_exit: &LocalsStateAtExit, ) -> bool; - - /// If this is a place like `x.f.g`, returns the local - /// `x`. Returns `None` if this is based in a static. - fn root_local(&self) -> Option; } impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { @@ -82,15 +78,4 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> { }, } } - - fn root_local(&self) -> Option { - let mut p = self; - loop { - match p { - Place::Projection(pi) => p = &pi.base, - Place::Base(PlaceBase::Static(_)) => return None, - Place::Base(PlaceBase::Local(l)) => return Some(*l), - } - } - } } From 49f01413748f536f49b3d14845dbe5dd717b6b84 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Thu, 2 May 2019 01:07:44 +0200 Subject: [PATCH 3/3] Implement base_local iteratively --- src/librustc/mir/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 0dc23f5ce47e5..f23ff47b5ff66 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2055,10 +2055,13 @@ impl<'tcx> Place<'tcx> { /// Finds the innermost `Local` from this `Place`. pub fn base_local(&self) -> Option { - match self { - Place::Base(PlaceBase::Local(local)) => Some(*local), - Place::Projection(box Projection { base, elem: _ }) => base.base_local(), - Place::Base(PlaceBase::Static(..)) => None, + let mut place = self; + loop { + match place { + Place::Projection(proj) => place = &proj.base, + Place::Base(PlaceBase::Static(_)) => return None, + Place::Base(PlaceBase::Local(local)) => return Some(*local), + } } }