Skip to content

Commit 96ac02b

Browse files
Use new Place::is_indirect API where possible
1 parent 8648732 commit 96ac02b

File tree

2 files changed

+11
-29
lines changed

2 files changed

+11
-29
lines changed

src/librustc_mir/borrow_check/path_utils.rs

+7-16
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::borrow_check::places_conflict;
33
use crate::borrow_check::AccessDepth;
44
use crate::dataflow::indexes::BorrowIndex;
55
use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase};
6-
use rustc::mir::{ProjectionElem, BorrowKind};
6+
use rustc::mir::BorrowKind;
77
use rustc::ty::{self, TyCtxt};
88
use rustc_data_structures::graph::dominators::Dominators;
99

@@ -133,20 +133,11 @@ pub(super) fn is_active<'tcx>(
133133
/// Determines if a given borrow is borrowing local data
134134
/// This is called for all Yield statements on movable generators
135135
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-
}
136+
match place.base {
137+
PlaceBase::Static(_) => false,
149138

150-
true
151-
})
139+
// Reborrow of already borrowed data is ignored
140+
// Any errors will be caught on the initial borrow
141+
PlaceBase::Local(_) => !place.is_indirect(),
142+
}
152143
}

src/librustc_mir/dataflow/impls/borrowed_locals.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,10 @@ struct BorrowedLocalsVisitor<'gk> {
9393
}
9494

9595
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-
})
96+
match place.base {
97+
PlaceBase::Local(local) if !place.is_indirect() => Some(local),
98+
_ => None,
99+
}
109100
}
110101

111102
impl<'tcx> Visitor<'tcx> for BorrowedLocalsVisitor<'_> {

0 commit comments

Comments
 (0)