Skip to content

Commit b922e8a

Browse files
committed
Make dest_needs_borrow iterate instead of recurse
1 parent 4dbc7f9 commit b922e8a

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/librustc_mir/transform/inline.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -440,19 +440,22 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
440440
// writes to `i`. To prevent this we need to create a temporary
441441
// borrow of the place and pass the destination as `*temp` instead.
442442
fn dest_needs_borrow(place: &Place<'_>) -> bool {
443-
match *place {
444-
Place::Projection(ref p) => {
445-
match p.elem {
443+
place.iterate(|place_base, place_projection| {
444+
for proj in place_projection {
445+
match proj.elem {
446446
ProjectionElem::Deref |
447-
ProjectionElem::Index(_) => true,
448-
_ => dest_needs_borrow(&p.base)
447+
ProjectionElem::Index(_) => return true,
448+
_ => {}
449449
}
450450
}
451-
// Static variables need a borrow because the callee
452-
// might modify the same static.
453-
Place::Base(PlaceBase::Static(_)) => true,
454-
_ => false
455-
}
451+
452+
match place_base {
453+
// Static variables need a borrow because the callee
454+
// might modify the same static.
455+
PlaceBase::Static(_) => true,
456+
_ => false
457+
}
458+
})
456459
}
457460

458461
let dest = if dest_needs_borrow(&destination.0) {

0 commit comments

Comments
 (0)