File tree 1 file changed +13
-0
lines changed
src/librustc_mir/transform/check_consts
1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change @@ -705,6 +705,19 @@ fn place_as_reborrow(
705
705
return None ;
706
706
}
707
707
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.
708
721
let inner_ty = Place :: ty_from ( & place. base , inner, body, tcx) . ty ;
709
722
match inner_ty. kind {
710
723
ty:: Ref ( ..) => Some ( inner) ,
You can’t perform that action at this time.
0 commit comments