@@ -502,9 +502,33 @@ impl<'tcx> Validator<'_, 'tcx> {
502502 fn validate_place ( & self , place : PlaceRef < ' tcx > ) -> Result < ( ) , Unpromotable > {
503503 match place {
504504 PlaceRef { local, projection : [ ] } => self . validate_local ( local) ,
505- PlaceRef { local : _ , projection : [ proj_base @ .., elem] } => {
505+ PlaceRef { local, projection : [ proj_base @ .., elem] } => {
506506 match * elem {
507- ProjectionElem :: Deref | ProjectionElem :: Downcast ( ..) => {
507+ ProjectionElem :: Deref => {
508+ let mut not_promotable = true ;
509+ if let TempState :: Defined { location, .. } = self . temps [ local] {
510+ let def_stmt =
511+ self . body [ location. block ] . statements . get ( location. statement_index ) ;
512+ if let Some ( Statement {
513+ kind :
514+ StatementKind :: Assign ( box ( _, Rvalue :: Use ( Operand :: Constant ( c) ) ) ) ,
515+ ..
516+ } ) = def_stmt
517+ {
518+ if let Some ( did) = c. check_static_ptr ( self . tcx ) {
519+ if let Some ( hir:: ConstContext :: Static ( ..) ) = self . const_kind {
520+ if !self . tcx . is_thread_local_static ( did) {
521+ not_promotable = false ;
522+ }
523+ }
524+ }
525+ }
526+ }
527+ if not_promotable {
528+ return Err ( Unpromotable ) ;
529+ }
530+ }
531+ ProjectionElem :: Downcast ( ..) => {
508532 return Err ( Unpromotable ) ;
509533 }
510534
0 commit comments