@@ -243,13 +243,29 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
243243 return ;
244244 }
245245
246+ if self . tcx . features ( ) . const_let {
247+ let mut dest = dest;
248+ let index = loop {
249+ match dest {
250+ Place :: Local ( index) => break * index,
251+ Place :: Projection ( proj) => dest = & proj. base ,
252+ Place :: Promoted ( ..) | Place :: Static ( ..) => {
253+ // Catch more errors in the destination.
254+ self . visit_place (
255+ dest,
256+ PlaceContext :: MutatingUse ( MutatingUseContext :: Store ) ,
257+ location
258+ ) ;
259+ return ;
260+ }
261+ }
262+ } ;
263+ debug ! ( "store to var {:?}" , index) ;
264+ self . local_qualif [ index] = Some ( self . qualif ) ;
265+ return ;
266+ }
267+
246268 match * dest {
247- Place :: Local ( index) if ( self . mir . local_kind ( index) == LocalKind :: Var ||
248- self . mir . local_kind ( index) == LocalKind :: Arg ) &&
249- self . tcx . sess . features_untracked ( ) . const_let => {
250- debug ! ( "store to var {:?}" , index) ;
251- self . local_qualif [ index] = Some ( self . qualif ) ;
252- }
253269 Place :: Local ( index) if self . mir . local_kind ( index) == LocalKind :: Temp ||
254270 self . mir . local_kind ( index) == LocalKind :: ReturnPointer => {
255271 debug ! ( "store to {:?} (temp or return pointer)" , index) ;
@@ -478,6 +494,12 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
478494
479495 // Only allow statics (not consts) to refer to other statics.
480496 if self . mode == Mode :: Static || self . mode == Mode :: StaticMut {
497+ if context. is_mutating_use ( ) {
498+ self . tcx . sess . span_err (
499+ self . span ,
500+ "cannot mutate statics in the initializer of another static" ,
501+ ) ;
502+ }
481503 return ;
482504 }
483505 self . add ( Qualif :: NOT_CONST ) ;
0 commit comments