Skip to content

Commit

Permalink
Rollup merge of rust-lang#61242 - spastorino:dest-needs-borrow-iterat…
Browse files Browse the repository at this point in the history
…e, r=oli-obk

Make dest_needs_borrow iterate instead of recurse

r? @oli-obk
  • Loading branch information
Centril committed May 28, 2019
2 parents c33b349 + b922e8a commit ffb4ceb
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/librustc_mir/transform/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,19 +440,22 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
// writes to `i`. To prevent this we need to create a temporary
// borrow of the place and pass the destination as `*temp` instead.
fn dest_needs_borrow(place: &Place<'_>) -> bool {
match *place {
Place::Projection(ref p) => {
match p.elem {
place.iterate(|place_base, place_projection| {
for proj in place_projection {
match proj.elem {
ProjectionElem::Deref |
ProjectionElem::Index(_) => true,
_ => dest_needs_borrow(&p.base)
ProjectionElem::Index(_) => return true,
_ => {}
}
}
// Static variables need a borrow because the callee
// might modify the same static.
Place::Base(PlaceBase::Static(_)) => true,
_ => false
}

match place_base {
// Static variables need a borrow because the callee
// might modify the same static.
PlaceBase::Static(_) => true,
_ => false
}
})
}

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

0 comments on commit ffb4ceb

Please sign in to comment.