Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Prev Previous commit
qualify_consts: move thread_local condition out.
  • Loading branch information
Centril committed Aug 31, 2019
commit 0a8a3dd88a1216e7487b8e39179fbac16d07bafe
16 changes: 3 additions & 13 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1648,9 +1648,9 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
remove_drop_and_storage_dead_on_promoted_locals(body, promoted_temps);
}

if let Mode::Static = mode {
if mode == Mode::Static && !tcx.has_attr(def_id, sym::thread_local) {
// `static`s (not `static mut`s) which are not `#[thread_local]` must be `Sync`.
check_non_thread_local_static_is_sync(tcx, body, def_id, hir_id);
check_static_is_sync(tcx, body, hir_id);
}
}
}
Expand Down Expand Up @@ -1739,17 +1739,7 @@ fn remove_drop_and_storage_dead_on_promoted_locals(
}
}

fn check_non_thread_local_static_is_sync(
tcx: TyCtxt<'tcx>,
body: &mut Body<'tcx>,
def_id: DefId,
hir_id: HirId,
) {
// `#[thread_local]` statics don't have to be `Sync`.
if tcx.has_attr(def_id, sym::thread_local) {
return;
}

fn check_static_is_sync(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, hir_id: HirId) {
let ty = body.return_ty();
tcx.infer_ctxt().enter(|infcx| {
let cause = traits::ObligationCause::new(body.span, hir_id, traits::SharedStatic);
Expand Down