Skip to content

Commit b4f6e5b

Browse files
authored
Rollup merge of #61093 - spastorino:borrow-of-local-data-iterate, r=oli-obk
Make borrow_of_local_data iterate instead of recurse r? @oli-obk
2 parents 1ce0288 + 9613779 commit b4f6e5b

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

src/librustc_mir/borrow_check/path_utils.rs

+13-15
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,20 @@ pub(super) fn is_active<'tcx>(
131131
/// Determines if a given borrow is borrowing local data
132132
/// This is called for all Yield statements on movable generators
133133
pub(super) fn borrow_of_local_data<'tcx>(place: &Place<'tcx>) -> bool {
134-
match place {
135-
Place::Base(PlaceBase::Static(..)) => false,
136-
Place::Base(PlaceBase::Local(..)) => true,
137-
Place::Projection(box proj) => {
138-
match proj.elem {
139-
// Reborrow of already borrowed data is ignored
140-
// Any errors will be caught on the initial borrow
141-
ProjectionElem::Deref => false,
134+
place.iterate(|place_base, place_projection| {
135+
match place_base {
136+
PlaceBase::Static(..) => return false,
137+
PlaceBase::Local(..) => {},
138+
}
142139

143-
// For interior references and downcasts, find out if the base is local
144-
ProjectionElem::Field(..)
145-
| ProjectionElem::Index(..)
146-
| ProjectionElem::ConstantIndex { .. }
147-
| ProjectionElem::Subslice { .. }
148-
| ProjectionElem::Downcast(..) => borrow_of_local_data(&proj.base),
140+
for proj in place_projection {
141+
// Reborrow of already borrowed data is ignored
142+
// Any errors will be caught on the initial borrow
143+
if proj.elem == ProjectionElem::Deref {
144+
return false;
149145
}
150146
}
151-
}
147+
148+
true
149+
})
152150
}

0 commit comments

Comments
 (0)