Skip to content

Commit a70ac50

Browse files
Don't treat a reference to a static as a reborrow
They now look the same in the MIR after #66587.
1 parent 5b1e10b commit a70ac50

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/librustc_mir/transform/check_consts/validation.rs

+13
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,19 @@ fn place_as_reborrow(
705705
return None;
706706
}
707707

708+
// A borrow of a `static` also looks like `&(*_1)` in the MIR, but `_1` is a `const`
709+
// that points to the allocation for the static. Don't treat these as reborrows.
710+
if let PlaceBase::Local(local) = place.base {
711+
let decl = &body.local_decls[local];
712+
if let LocalInfo::StaticRef { .. } = decl.local_info {
713+
return None;
714+
}
715+
}
716+
717+
// Ensure the type being derefed is a reference and not a raw pointer.
718+
//
719+
// This is sufficient to prevent an access to a `static mut` from being marked as a
720+
// reborrow, even if the check above were to disappear.
708721
let inner_ty = Place::ty_from(&place.base, inner, body, tcx).ty;
709722
match inner_ty.kind {
710723
ty::Ref(..) => Some(inner),

0 commit comments

Comments
 (0)