File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
src/librustc_mir/transform/check_consts Expand file tree Collapse file tree 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(
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) ,
You can’t perform that action at this time.
0 commit comments