Skip to content

Commit 0764641

Browse files
Use new Place::base_direct API when possible
Its functionality is duplicated in `borrowed_locals.rs` and `path_utils.rs`
1 parent 905818f commit 0764641

File tree

2 files changed

+7
-37
lines changed

2 files changed

+7
-37
lines changed

src/librustc_mir/borrow_check/path_utils.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ use crate::borrow_check::borrow_set::{BorrowSet, BorrowData, TwoPhaseActivation}
22
use crate::borrow_check::places_conflict;
33
use crate::borrow_check::AccessDepth;
44
use crate::dataflow::indexes::BorrowIndex;
5-
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
6-
use rustc::mir::{ProjectionElem, BorrowKind};
5+
use rustc::mir::{BasicBlock, BorrowKind, Location, Body, Place, PlaceBase};
76
use rustc::ty::{self, TyCtxt};
87
use rustc_data_structures::graph::dominators::Dominators;
98

@@ -132,21 +131,8 @@ pub(super) fn is_active<'tcx>(
132131

133132
/// Determines if a given borrow is borrowing local data
134133
/// This is called for all Yield statements on movable generators
135-
pub(super) fn borrow_of_local_data(place: &Place<'_>) -> bool {
136-
place.iterate(|place_base, place_projection| {
137-
match place_base {
138-
PlaceBase::Static(..) => return false,
139-
PlaceBase::Local(..) => {},
140-
}
141-
142-
for proj in place_projection {
143-
// Reborrow of already borrowed data is ignored
144-
// Any errors will be caught on the initial borrow
145-
if proj.elem == ProjectionElem::Deref {
146-
return false;
147-
}
148-
}
149-
150-
true
151-
})
134+
pub(super) fn borrow_of_local_data<'tcx>(place: &Place<'tcx>) -> bool {
135+
place.base_direct()
136+
.and_then(PlaceBase::local)
137+
.is_some()
152138
}

src/librustc_mir/dataflow/impls/borrowed_locals.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {
6464
// Drop terminators borrows the location
6565
TerminatorKind::Drop { location, .. } |
6666
TerminatorKind::DropAndReplace { location, .. } => {
67-
if let Some(local) = find_local(location) {
67+
if let Some(local) = location.base_direct().and_then(PlaceBase::local) {
6868
trans.gen(local);
6969
}
7070
}
@@ -92,28 +92,12 @@ struct BorrowedLocalsVisitor<'gk> {
9292
trans: &'gk mut GenKillSet<Local>,
9393
}
9494

95-
fn find_local(place: &Place<'_>) -> Option<Local> {
96-
place.iterate(|place_base, place_projection| {
97-
for proj in place_projection {
98-
if proj.elem == ProjectionElem::Deref {
99-
return None;
100-
}
101-
}
102-
103-
if let PlaceBase::Local(local) = place_base {
104-
Some(*local)
105-
} else {
106-
None
107-
}
108-
})
109-
}
110-
11195
impl<'tcx> Visitor<'tcx> for BorrowedLocalsVisitor<'_> {
11296
fn visit_rvalue(&mut self,
11397
rvalue: &Rvalue<'tcx>,
11498
location: Location) {
11599
if let Rvalue::Ref(_, _, ref place) = *rvalue {
116-
if let Some(local) = find_local(place) {
100+
if let Some(local) = place.base_direct().and_then(PlaceBase::local) {
117101
self.trans.gen(local);
118102
}
119103
}

0 commit comments

Comments
 (0)