@@ -1687,31 +1687,9 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
16871687 }
16881688 }
16891689
1690- // Statics must be Sync.
16911690 if let Mode :: Static = mode {
1692- // `#[thread_local]` statics don't have to be `Sync`.
1693- for attr in & tcx. get_attrs ( def_id) [ ..] {
1694- if attr. check_name ( sym:: thread_local) {
1695- return ;
1696- }
1697- }
1698- let ty = body. return_ty ( ) ;
1699- tcx. infer_ctxt ( ) . enter ( |infcx| {
1700- let param_env = ty:: ParamEnv :: empty ( ) ;
1701- let cause = traits:: ObligationCause :: new ( body. span , hir_id, traits:: SharedStatic ) ;
1702- let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
1703- fulfillment_cx. register_bound ( & infcx,
1704- param_env,
1705- ty,
1706- tcx. require_lang_item (
1707- lang_items:: SyncTraitLangItem ,
1708- Some ( body. span )
1709- ) ,
1710- cause) ;
1711- if let Err ( err) = fulfillment_cx. select_all_or_error ( & infcx) {
1712- infcx. report_fulfillment_errors ( & err, None , false ) ;
1713- }
1714- } ) ;
1691+ // `static`s (not `static mut`s) which are not `#[thread_local]` must be `Sync`.
1692+ check_non_thread_local_static_is_sync ( tcx, body, def_id, hir_id) ;
17151693 }
17161694 }
17171695}
@@ -1760,6 +1738,29 @@ fn check_short_circuiting_in_const_local(tcx: TyCtxt<'_>, body: &mut Body<'tcx>,
17601738 }
17611739}
17621740
1741+ fn check_non_thread_local_static_is_sync (
1742+ tcx : TyCtxt < ' tcx > ,
1743+ body : & mut Body < ' tcx > ,
1744+ def_id : DefId ,
1745+ hir_id : HirId ,
1746+ ) {
1747+ // `#[thread_local]` statics don't have to be `Sync`.
1748+ if tcx. has_attr ( def_id, sym:: thread_local) {
1749+ return ;
1750+ }
1751+
1752+ let ty = body. return_ty ( ) ;
1753+ tcx. infer_ctxt ( ) . enter ( |infcx| {
1754+ let cause = traits:: ObligationCause :: new ( body. span , hir_id, traits:: SharedStatic ) ;
1755+ let mut fulfillment_cx = traits:: FulfillmentContext :: new ( ) ;
1756+ let sync_def_id = tcx. require_lang_item ( lang_items:: SyncTraitLangItem , Some ( body. span ) ) ;
1757+ fulfillment_cx. register_bound ( & infcx, ty:: ParamEnv :: empty ( ) , ty, sync_def_id, cause) ;
1758+ if let Err ( err) = fulfillment_cx. select_all_or_error ( & infcx) {
1759+ infcx. report_fulfillment_errors ( & err, None , false ) ;
1760+ }
1761+ } ) ;
1762+ }
1763+
17631764fn args_required_const ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> Option < FxHashSet < usize > > {
17641765 let attrs = tcx. get_attrs ( def_id) ;
17651766 let attr = attrs. iter ( ) . find ( |a| a. check_name ( sym:: rustc_args_required_const) ) ?;
0 commit comments