Skip to content

Commit

Permalink
Don't treat a reference to a static as a reborrow
Browse files Browse the repository at this point in the history
They now look the same in the MIR after rust-lang#66587.
  • Loading branch information
ecstatic-morse committed Nov 28, 2019
1 parent 5b1e10b commit a70ac50
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/librustc_mir/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,19 @@ fn place_as_reborrow(
return None;
}

// A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
// that points to the allocation for the static. Don't treat these as reborrows.
if let PlaceBase::Local(local) = place.base {
let decl = &body.local_decls[local];
if let LocalInfo::StaticRef { .. } = decl.local_info {
return None;
}
}

// Ensure the type being derefed is a reference and not a raw pointer.
//
// This is sufficient to prevent an access to a `static mut` from being marked as a
// reborrow, even if the check above were to disappear.
let inner_ty = Place::ty_from(&place.base, inner, body, tcx).ty;
match inner_ty.kind {
ty::Ref(..) => Some(inner),
Expand Down

0 comments on commit a70ac50

Please sign in to comment.