about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2025-07-26 21:46:20 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2025-07-26 21:53:13 +0000
commit8817572b4595df352e6a7fdd56422fb07cd28d89 (patch)
tree5375a7a84cab2e711becf0bded7836c8381a0b4a /compiler/rustc_hir_analysis/src
parent7c6496145f86133655a941e0dafd5dfa368514d4 (diff)
downloadrust-8817572b4595df352e6a7fdd56422fb07cd28d89.tar.gz
rust-8817572b4595df352e6a7fdd56422fb07cd28d89.zip
Do not check Sync during type_of.
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/check/check.rs2
-rw-r--r--compiler/rustc_hir_analysis/src/check/wfcheck.rs5
-rw-r--r--compiler/rustc_hir_analysis/src/collect/type_of.rs4
3 files changed, 7 insertions, 4 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs
index 07ca64e6144..f2be2a65716 100644
--- a/compiler/rustc_hir_analysis/src/check/check.rs
+++ b/compiler/rustc_hir_analysis/src/check/check.rs
@@ -767,6 +767,8 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
                 DefKind::Static { .. } => {
                     check_static_inhabited(tcx, def_id);
                     check_static_linkage(tcx, def_id);
+                    let ty = tcx.type_of(def_id).instantiate_identity();
+                    res = res.and(wfcheck::check_static_item(tcx, def_id, ty, true));
                 }
                 DefKind::Const => res = res.and(wfcheck::check_const_item(tcx, def_id)),
                 _ => unreachable!(),
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
index e8d962467b3..a62efed13bc 100644
--- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs
+++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs
@@ -1184,6 +1184,7 @@ pub(crate) fn check_static_item<'tcx>(
     tcx: TyCtxt<'tcx>,
     item_id: LocalDefId,
     ty: Ty<'tcx>,
+    should_check_for_sync: bool,
 ) -> Result<(), ErrorGuaranteed> {
     enter_wf_checking_ctxt(tcx, item_id, |wfcx| {
         let span = tcx.ty_span(item_id);
@@ -1212,9 +1213,9 @@ pub(crate) fn check_static_item<'tcx>(
         }
 
         // Ensure that the end result is `Sync` in a non-thread local `static`.
-        let should_check_for_sync = tcx.static_mutability(item_id.to_def_id())
-            == Some(hir::Mutability::Not)
+        let should_check_for_sync = should_check_for_sync
             && !is_foreign_item
+            && tcx.static_mutability(item_id.to_def_id()) == Some(hir::Mutability::Not)
             && !tcx.is_thread_local_static(item_id.to_def_id());
 
         if should_check_for_sync {
diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs
index f84bd2a5fb3..68a91212e50 100644
--- a/compiler/rustc_hir_analysis/src/collect/type_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs
@@ -221,7 +221,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
                     let ty = icx.lower_ty(ty);
                     // MIR relies on references to statics being scalars.
                     // Verify that here to avoid ill-formed MIR.
-                    match check_static_item(tcx, def_id, ty) {
+                    match check_static_item(tcx, def_id, ty, false) {
                         Ok(()) => ty,
                         Err(guar) => Ty::new_error(tcx, guar),
                     }
@@ -286,7 +286,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
                 let ty = icx.lower_ty(ty);
                 // MIR relies on references to statics being scalars.
                 // Verify that here to avoid ill-formed MIR.
-                match check_static_item(tcx, def_id, ty) {
+                match check_static_item(tcx, def_id, ty, false) {
                     Ok(()) => ty,
                     Err(guar) => Ty::new_error(tcx, guar),
                 }