Skip to content

Commit df5a557

Browse files
authored
Rollup merge of rust-lang#60486 - spastorino:place-related-refactors, r=oli-obk
Place related refactors Meanwhile I was working on Place 2 I'm finding some little things that I had on my branch but preferred to land a separate PR for things that are simpler to merge. r? @oli-obk
2 parents 0c9f635 + 49f0141 commit df5a557

File tree

4 files changed

+9
-22
lines changed

4 files changed

+9
-22
lines changed

src/librustc/mir/mod.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -2055,10 +2055,13 @@ impl<'tcx> Place<'tcx> {
20552055

20562056
/// Finds the innermost `Local` from this `Place`.
20572057
pub fn base_local(&self) -> Option<Local> {
2058-
match self {
2059-
Place::Base(PlaceBase::Local(local)) => Some(*local),
2060-
Place::Projection(box Projection { base, elem: _ }) => base.base_local(),
2061-
Place::Base(PlaceBase::Static(..)) => None,
2058+
let mut place = self;
2059+
loop {
2060+
match place {
2061+
Place::Projection(proj) => place = &proj.base,
2062+
Place::Base(PlaceBase::Static(_)) => return None,
2063+
Place::Base(PlaceBase::Local(local)) => return Some(*local),
2064+
}
20622065
}
20632066
}
20642067

src/librustc_mir/borrow_check/borrow_set.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
210210

211211
self.insert_as_pending_if_two_phase(location, &assigned_place, kind, idx);
212212

213-
if let Some(local) = borrowed_place.root_local() {
213+
if let Some(local) = borrowed_place.base_local() {
214214
self.local_map.entry(local).or_default().insert(idx);
215215
}
216216
}

src/librustc_mir/borrow_check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1831,7 +1831,6 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18311831
}
18321832

18331833
place = base;
1834-
continue;
18351834
}
18361835
}
18371836
}

src/librustc_mir/borrow_check/place_ext.rs

+1-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc::hir;
22
use rustc::mir::ProjectionElem;
3-
use rustc::mir::{Local, Mir, Place, PlaceBase, Mutability, Static, StaticKind};
3+
use rustc::mir::{Mir, Place, PlaceBase, Mutability, Static, StaticKind};
44
use rustc::ty::{self, TyCtxt};
55
use crate::borrow_check::borrow_set::LocalsStateAtExit;
66

@@ -16,10 +16,6 @@ crate trait PlaceExt<'tcx> {
1616
mir: &Mir<'tcx>,
1717
locals_state_at_exit: &LocalsStateAtExit,
1818
) -> bool;
19-
20-
/// If this is a place like `x.f.g`, returns the local
21-
/// `x`. Returns `None` if this is based in a static.
22-
fn root_local(&self) -> Option<Local>;
2319
}
2420

2521
impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
@@ -82,15 +78,4 @@ impl<'tcx> PlaceExt<'tcx> for Place<'tcx> {
8278
},
8379
}
8480
}
85-
86-
fn root_local(&self) -> Option<Local> {
87-
let mut p = self;
88-
loop {
89-
match p {
90-
Place::Projection(pi) => p = &pi.base,
91-
Place::Base(PlaceBase::Static(_)) => return None,
92-
Place::Base(PlaceBase::Local(l)) => return Some(*l),
93-
}
94-
}
95-
}
9681
}

0 commit comments

Comments
 (0)