From dd43deb3daf4ef1c6573d1d3beeb3a478c87c5df Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 11 Feb 2026 16:11:53 +0100 Subject: [PATCH 1/2] Add AllowSharedStatic This is a new trait that is used by the language in bounds for `static` items instead of `Sync`. It is implemented by all `T: Sync`, as well as by `UnsafeCell`. --- .../example/mini_core.rs | 4 +++ .../rustc_codegen_gcc/example/mini_core.rs | 4 +++ compiler/rustc_hir/src/lang_items.rs | 1 + .../rustc_hir_analysis/src/check/check.rs | 2 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 10 +++---- .../rustc_hir_analysis/src/collect/type_of.rs | 8 +++-- compiler/rustc_middle/src/traits/mod.rs | 2 +- compiler/rustc_span/src/symbol.rs | 1 + .../src/error_reporting/traits/suggestions.rs | 1 + library/core/src/marker.rs | 29 +++++++++++++++++++ library/rtstartup/rsbegin.rs | 5 ++-- library/rtstartup/rsend.rs | 6 ++-- tests/auxiliary/minicore.rs | 4 +++ .../arm64ec-import-export-static/export.rs | 6 ++-- .../min-global-align/min_global_align.rs | 8 ++--- tests/ui/lang-items/issue-87573.rs | 8 ++--- ...lobal-variable-promotion-error-7364.stderr | 1 + tests/ui/static/static-requires-lang-item.rs | 16 ++++++++++ .../static/static-requires-lang-item.stderr | 8 +++++ tests/ui/static/unsafe-cell.rs | 14 +++++++++ tests/ui/static/unsafe-cell.stderr | 18 ++++++++++++ .../ui/statics/issue-17718-static-sync.stderr | 1 + .../unsizing-wfcheck-issue-127299.stderr | 1 + 23 files changed, 133 insertions(+), 25 deletions(-) create mode 100644 tests/ui/static/static-requires-lang-item.rs create mode 100644 tests/ui/static/static-requires-lang-item.stderr create mode 100644 tests/ui/static/unsafe-cell.rs create mode 100644 tests/ui/static/unsafe-cell.stderr diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 301547cadaf7c..4310957030677 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -104,6 +104,10 @@ unsafe impl Sync for f32 {} unsafe impl<'a, T: PointeeSized> Sync for &'a T {} unsafe impl Sync for [T; N] {} +#[lang = "allow_shared_static"] +unsafe trait AllowSharedStatic {} +unsafe impl AllowSharedStatic for T {} + #[lang = "freeze"] unsafe auto trait Freeze {} diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index 0aba44a88c5a4..bb4d647ac0f76 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -111,6 +111,10 @@ unsafe impl Sync for char {} unsafe impl<'a, T: PointeeSized> Sync for &'a T {} unsafe impl Sync for [u8; 16] {} +#[lang = "allow_shared_static"] +unsafe trait AllowSharedStatic {} +unsafe impl AllowSharedStatic for T {} + #[lang = "freeze"] unsafe auto trait Freeze {} diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 557f76208bfe6..6f220c641bae5 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -231,6 +231,7 @@ language_item_table! { IndexMut, sym::index_mut, index_mut_trait, Target::Trait, GenericRequirement::Exact(1); UnsafeCell, sym::unsafe_cell, unsafe_cell_type, Target::Struct, GenericRequirement::None; + AllowSharedStatic, sym::allow_shared_static, allow_shared_static_trait, Target::Trait, GenericRequirement::Exact(0); UnsafePinned, sym::unsafe_pinned, unsafe_pinned_type, Target::Struct, GenericRequirement::None; VaList, sym::va_list, va_list, Target::Struct, GenericRequirement::None; diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 1bee7a72229a1..c89820ee8d54c 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -770,7 +770,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), 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, /* should_check_for_sync */ true, + tcx, def_id, ty, /* should_check_allow_in_shared_static */ true, )); // Only `Node::Item` and `Node::ForeignItem` still have HIR based diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index ceb0e138a0dae..da2e1657b79ed 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1228,7 +1228,7 @@ pub(crate) fn check_static_item<'tcx>( tcx: TyCtxt<'tcx>, item_id: LocalDefId, ty: Ty<'tcx>, - should_check_for_sync: bool, + should_check_allow_in_shared_static: bool, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, item_id, |wfcx| { let span = tcx.ty_span(item_id); @@ -1263,13 +1263,13 @@ 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 = should_check_for_sync + // Ensure that the end result is `Sync` or `UnsafeCell` in a non-thread local `static`. + let should_check_allow_in_shared_static = should_check_allow_in_shared_static && !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 { + if should_check_allow_in_shared_static { wfcx.register_bound( traits::ObligationCause::new( span, @@ -1278,7 +1278,7 @@ pub(crate) fn check_static_item<'tcx>( ), wfcx.param_env, item_ty, - tcx.require_lang_item(LangItem::Sync, span), + tcx.require_lang_item(LangItem::AllowSharedStatic, span), ); } Ok(()) diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 23df419d06a70..d983f7fcddab9 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -131,7 +131,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ // Verify that here to avoid ill-formed MIR. // We skip the `Sync` check to avoid cycles for type-alias-impl-trait, // relying on the fact that non-Sync statics don't ICE the rest of the compiler. - match check_static_item(tcx, def_id, ty, /* should_check_for_sync */ false) { + match check_static_item( + tcx, def_id, ty, /* should_check_allow_in_shared_static */ false, + ) { Ok(()) => ty, Err(guar) => Ty::new_error(tcx, guar), } @@ -199,7 +201,9 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ // Verify that here to avoid ill-formed MIR. // We skip the `Sync` check to avoid cycles for type-alias-impl-trait, // relying on the fact that non-Sync statics don't ICE the rest of the compiler. - match check_static_item(tcx, def_id, ty, /* should_check_for_sync */ false) { + match check_static_item( + tcx, def_id, ty, /* should_check_allow_in_shared_static */ false, + ) { Ok(()) => ty, Err(guar) => Ty::new_error(tcx, guar), } diff --git a/compiler/rustc_middle/src/traits/mod.rs b/compiler/rustc_middle/src/traits/mod.rs index 2fca85c9f2f19..26051d73132a6 100644 --- a/compiler/rustc_middle/src/traits/mod.rs +++ b/compiler/rustc_middle/src/traits/mod.rs @@ -269,7 +269,7 @@ pub enum ObligationCauseCode<'tcx> { /// Constant expressions must be sized. SizedConstOrStatic, - /// `static` items must have `Sync` type. + /// `static` items must have `Sync` or `UnsafeCell` type (`AllowSharedStatic`). SharedStatic, /// Derived obligation (i.e. theoretical `where` clause) on a built-in diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 0f248925602ff..e6b4093326f94 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -461,6 +461,7 @@ symbols! { allow_fail, allow_internal_unsafe, allow_internal_unstable, + allow_shared_static, altivec, alu32, always, diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 63fd61cb257b2..549f0f9ea240e 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -3400,6 +3400,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { )); } ObligationCauseCode::SharedStatic => { + // TODO: Add note about `UnsafeCell` here too? err.note("shared static variables must have a type that implements `Sync`"); } ObligationCauseCode::BuiltinDerived(ref data) => { diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 57416455e9de8..1cd00d4b95258 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -676,6 +676,35 @@ impl !Sync for *const T {} #[stable(feature = "rust1", since = "1.0.0")] impl !Sync for *mut T {} +/// Whether a type is usable in shared statics. +/// +/// TODO. +#[lang = "allow_shared_static"] +#[unstable(feature = "allow_shared_static_trait", issue = "none")] +#[rustc_on_unimplemented( + message = "`{Self}` cannot be shared between threads safely", + label = "`{Self}` cannot be shared between threads safely" +)] +pub unsafe trait AllowSharedStatic {} + +// SAFETY: All `T: Sync` types are usable in shared statics. +// +// NOTE: The `MetaSized` bound is mostly a lie, as only sized types can be +// used directly in statics. But this is already enforced by the compiler. +#[unstable(feature = "allow_shared_static_trait", issue = "none")] +unsafe impl AllowSharedStatic for T {} + +// SAFETY: `UnsafeCell` could (and should) have been `Sync`, there +// is nothing inherent to `UnsafeCell` that forbids `Sync`. +// +// NOTE: Ideally, we'd have marked `UnsafeCell: Sync`, but that is a +// breaking change, since users rely upon `UnsafeCell` making their type +// `!Sync`. +// +// See also TODO link. +#[unstable(feature = "allow_shared_static_trait", issue = "none")] +unsafe impl AllowSharedStatic for UnsafeCell {} + /// Zero-sized type used to mark things that "act like" they own a `T`. /// /// Adding a `PhantomData` field to your type tells the compiler that your diff --git a/library/rtstartup/rsbegin.rs b/library/rtstartup/rsbegin.rs index 62d247fafb7ad..5307d04e2b212 100644 --- a/library/rtstartup/rsbegin.rs +++ b/library/rtstartup/rsbegin.rs @@ -30,8 +30,9 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -#[lang = "sync"] -auto trait Sync {} +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for T {} #[lang = "copy"] trait Copy {} #[lang = "freeze"] diff --git a/library/rtstartup/rsend.rs b/library/rtstartup/rsend.rs index d763971445069..56c034036a890 100644 --- a/library/rtstartup/rsend.rs +++ b/library/rtstartup/rsend.rs @@ -17,9 +17,9 @@ pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -#[lang = "sync"] -trait Sync {} -impl Sync for T {} +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for T {} #[lang = "copy"] trait Copy {} #[lang = "freeze"] diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index 95b217c130317..c670873a1b770 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -229,6 +229,10 @@ impl_marker_trait!( ] ); +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for T {} + #[lang = "drop_in_place"] fn drop_in_place(_: *mut T) {} diff --git a/tests/run-make/arm64ec-import-export-static/export.rs b/tests/run-make/arm64ec-import-export-static/export.rs index ca6ccf00ca17e..0c6fbf6dce765 100644 --- a/tests/run-make/arm64ec-import-export-static/export.rs +++ b/tests/run-make/arm64ec-import-export-static/export.rs @@ -11,9 +11,9 @@ pub trait PointeeSized {} pub trait MetaSized: PointeeSized {} #[lang = "sized"] pub trait Sized: MetaSized {} -#[lang = "sync"] -trait Sync {} -impl Sync for i32 {} +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for i32 {} #[lang = "copy"] pub trait Copy {} impl Copy for i32 {} diff --git a/tests/run-make/min-global-align/min_global_align.rs b/tests/run-make/min-global-align/min_global_align.rs index fd6f83570300a..11b6f650106b3 100644 --- a/tests/run-make/min-global-align/min_global_align.rs +++ b/tests/run-make/min-global-align/min_global_align.rs @@ -29,10 +29,10 @@ trait Freeze {} // No `UnsafeCell`, so everything is `Freeze`. impl Freeze for T {} -#[lang = "sync"] -trait Sync {} -impl Sync for bool {} -impl Sync for &'static bool {} +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for bool {} +impl AllowSharedStatic for &'static bool {} #[lang = "drop_in_place"] pub unsafe fn drop_in_place(_: *mut T) {} diff --git a/tests/ui/lang-items/issue-87573.rs b/tests/ui/lang-items/issue-87573.rs index 97146df0ba766..178231cbe9926 100644 --- a/tests/ui/lang-items/issue-87573.rs +++ b/tests/ui/lang-items/issue-87573.rs @@ -19,9 +19,9 @@ trait Sized: MetaSized {} #[lang = "copy"] trait Copy {} -#[lang = "sync"] -trait Sync {} -impl Sync for bool {} +#[lang = "allow_shared_static"] +trait AllowSharedStatic {} +impl AllowSharedStatic for bool {} #[lang = "drop_in_place"] //~^ ERROR: `drop_in_place` lang item must be applied to a function with at least 1 generic argument @@ -31,4 +31,4 @@ fn drop_fn() { #[lang = "start"] //~^ ERROR: `start` lang item must be applied to a function with 1 generic argument -fn start(){} +fn start() {} diff --git a/tests/ui/static/global-variable-promotion-error-7364.stderr b/tests/ui/static/global-variable-promotion-error-7364.stderr index 9f0026621c139..a6d9eedea983b 100644 --- a/tests/ui/static/global-variable-promotion-error-7364.stderr +++ b/tests/ui/static/global-variable-promotion-error-7364.stderr @@ -9,6 +9,7 @@ LL | static boxed: Box> = Box::new(RefCell::new(0)); = note: required for `std::ptr::Unique>` to implement `Sync` note: required because it appears within the type `Box>` --> $SRC_DIR/alloc/src/boxed.rs:LL:COL + = note: required for `Box>` to implement `AllowSharedStatic` = note: shared static variables must have a type that implements `Sync` error[E0015]: cannot call non-const associated function `Box::>::new` in statics diff --git a/tests/ui/static/static-requires-lang-item.rs b/tests/ui/static/static-requires-lang-item.rs new file mode 100644 index 0000000000000..de20eaf5689ed --- /dev/null +++ b/tests/ui/static/static-requires-lang-item.rs @@ -0,0 +1,16 @@ +//! Test that creating statics requires the `AllowSharedStatic` language item. +#![feature(lang_items, no_core)] +#![no_core] +#![no_main] + +#[lang = "pointee_sized"] +trait PointeeSized {} +#[lang = "meta_sized"] +trait MetaSized: PointeeSized {} +#[lang = "sized"] +pub trait Sized: MetaSized {} +#[lang = "copy"] +trait Copy {} + +static FOO: () = (); +//~^ ERROR: requires `allow_shared_static` lang_item diff --git a/tests/ui/static/static-requires-lang-item.stderr b/tests/ui/static/static-requires-lang-item.stderr new file mode 100644 index 0000000000000..4acf793f97bbb --- /dev/null +++ b/tests/ui/static/static-requires-lang-item.stderr @@ -0,0 +1,8 @@ +error: requires `allow_shared_static` lang_item + --> $DIR/static-requires-lang-item.rs:15:13 + | +LL | static FOO: () = (); + | ^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/static/unsafe-cell.rs b/tests/ui/static/unsafe-cell.rs new file mode 100644 index 0000000000000..efac7cb2c9eb1 --- /dev/null +++ b/tests/ui/static/unsafe-cell.rs @@ -0,0 +1,14 @@ +//! Test `UnsafeCell` in `static`s. +use std::cell::UnsafeCell; + +// Works even though it isn't `Sync`. +#[allow(dead_code)] +static FOO: UnsafeCell = UnsafeCell::new(42); + +// Does not work, requires `unsafe impl Sync for Bar {}`. +struct Bar(UnsafeCell); +#[allow(dead_code)] +static BAR: Bar = Bar(UnsafeCell::new(42)); +//~^ ERROR: `UnsafeCell` cannot be shared between threads safely + +fn main() {} diff --git a/tests/ui/static/unsafe-cell.stderr b/tests/ui/static/unsafe-cell.stderr new file mode 100644 index 0000000000000..faa7cd29ee339 --- /dev/null +++ b/tests/ui/static/unsafe-cell.stderr @@ -0,0 +1,18 @@ +error[E0277]: `UnsafeCell` cannot be shared between threads safely + --> $DIR/unsafe-cell.rs:11:13 + | +LL | static BAR: Bar = Bar(UnsafeCell::new(42)); + | ^^^ `UnsafeCell` cannot be shared between threads safely + | + = help: within `Bar`, the trait `Sync` is not implemented for `UnsafeCell` +note: required because it appears within the type `Bar` + --> $DIR/unsafe-cell.rs:9:8 + | +LL | struct Bar(UnsafeCell); + | ^^^ + = note: required for `Bar` to implement `AllowSharedStatic` + = note: shared static variables must have a type that implements `Sync` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/statics/issue-17718-static-sync.stderr b/tests/ui/statics/issue-17718-static-sync.stderr index 3a6e3becbad33..7f085acfac838 100644 --- a/tests/ui/statics/issue-17718-static-sync.stderr +++ b/tests/ui/statics/issue-17718-static-sync.stderr @@ -9,6 +9,7 @@ help: the trait `Sync` is not implemented for `Foo` | LL | struct Foo; | ^^^^^^^^^^ + = note: required for `Foo` to implement `AllowSharedStatic` = note: shared static variables must have a type that implements `Sync` error: aborting due to 1 previous error diff --git a/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr b/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr index e401277a0209f..7355256c65acc 100644 --- a/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr +++ b/tests/ui/statics/unsizing-wfcheck-issue-127299.stderr @@ -35,6 +35,7 @@ note: required because it appears within the type `Lint` LL | pub struct Lint { | ^^^^ = note: required because it appears within the type `&'static Lint` + = note: required for `&'static Lint` to implement `AllowSharedStatic` = note: shared static variables must have a type that implements `Sync` error[E0038]: the trait `Qux` is not dyn compatible From b75138d6f0337629bccd55b977bc3cd991ad0317 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 11 Feb 2026 15:32:59 +0100 Subject: [PATCH 2/2] Remove Sync lang item The only place where it was required by the language was for checking usage in static variables (and that is now done by `AllowSharedStatic`), all other usage in the compiler was for diagnostics. --- compiler/rustc_codegen_cranelift/example/mini_core.rs | 1 - compiler/rustc_codegen_gcc/example/mini_core.rs | 1 - compiler/rustc_hir/src/lang_items.rs | 1 - compiler/rustc_hir_typeck/src/upvar.rs | 2 +- library/core/src/marker.rs | 1 - src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs | 2 +- src/tools/clippy/clippy_lints/src/non_copy_const.rs | 4 ++-- src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs | 1 - tests/auxiliary/minicore.rs | 1 - 9 files changed, 4 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_codegen_cranelift/example/mini_core.rs b/compiler/rustc_codegen_cranelift/example/mini_core.rs index 4310957030677..d485c6164189b 100644 --- a/compiler/rustc_codegen_cranelift/example/mini_core.rs +++ b/compiler/rustc_codegen_cranelift/example/mini_core.rs @@ -86,7 +86,6 @@ impl Copy for *const T {} impl Copy for *mut T {} impl Copy for Option {} -#[lang = "sync"] pub unsafe trait Sync {} unsafe impl Sync for bool {} diff --git a/compiler/rustc_codegen_gcc/example/mini_core.rs b/compiler/rustc_codegen_gcc/example/mini_core.rs index bb4d647ac0f76..e4590baf6043a 100644 --- a/compiler/rustc_codegen_gcc/example/mini_core.rs +++ b/compiler/rustc_codegen_gcc/example/mini_core.rs @@ -94,7 +94,6 @@ impl<'a, T: PointeeSized> Copy for &'a T {} impl Copy for *const T {} impl Copy for *mut T {} -#[lang = "sync"] pub unsafe trait Sync {} unsafe impl Sync for bool {} diff --git a/compiler/rustc_hir/src/lang_items.rs b/compiler/rustc_hir/src/lang_items.rs index 6f220c641bae5..842077f15baa1 100644 --- a/compiler/rustc_hir/src/lang_items.rs +++ b/compiler/rustc_hir/src/lang_items.rs @@ -178,7 +178,6 @@ language_item_table! { CloneFn, sym::clone_fn, clone_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; UseCloned, sym::use_cloned, use_cloned_trait, Target::Trait, GenericRequirement::None; TrivialClone, sym::trivial_clone, trivial_clone_trait, Target::Trait, GenericRequirement::None; - Sync, sym::sync, sync_trait, Target::Trait, GenericRequirement::Exact(0); DiscriminantKind, sym::discriminant_kind, discriminant_kind_trait, Target::Trait, GenericRequirement::None; /// The associated item of the `DiscriminantKind` trait. Discriminant, sym::discriminant_type, discriminant_type, Target::AssocTy, GenericRequirement::None; diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 767913ba5261a..56d86395d6f2f 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -1153,7 +1153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) -> Option>> { let auto_traits_def_id = [ self.tcx.lang_items().clone_trait(), - self.tcx.lang_items().sync_trait(), + self.tcx.get_diagnostic_item(sym::Sync), self.tcx.get_diagnostic_item(sym::Send), self.tcx.lang_items().unpin_trait(), self.tcx.get_diagnostic_item(sym::unwind_safe_trait), diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index 1cd00d4b95258..22c772172950b 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -583,7 +583,6 @@ pub trait BikeshedGuaranteedNoDrop {} /// [nomicon-send-and-sync]: ../../nomicon/send-and-sync.html #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Sync"] -#[lang = "sync"] #[rustc_on_unimplemented( on( Self = "core::cell::once::OnceCell", diff --git a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs b/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs index acfdfa65baeda..9b636887ece61 100644 --- a/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs +++ b/src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync { !matches!(arg.kind(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_))) }) && let Some(send) = cx.tcx.get_diagnostic_item(sym::Send) - && let Some(sync) = cx.tcx.lang_items().sync_trait() + && let Some(sync) = cx.tcx.get_diagnostic_item(sym::Sync) && let [is_send, is_sync] = [send, sync].map(|id| implements_trait(cx, arg_ty, id, &[])) && let reason = match (is_send, is_sync) { (false, false) => "neither `Send` nor `Sync`", diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index e09fc0a763665..9ac06f4d03919 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -725,10 +725,10 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { ident.span, "named constant with interior mutability", |diag| { - let Some(sync_trait) = cx.tcx.lang_items().sync_trait() else { + let Some(sync) = cx.tcx.get_diagnostic_item(sym::Sync) else { return; }; - if implements_trait(cx, ty, sync_trait, &[]) { + if implements_trait(cx, ty, sync, &[]) { diag.help("did you mean to make this a `static` item"); } else { diag.help("did you mean to make this a `thread_local!` item"); diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs index fef92c89b145a..2a6dbc2262090 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs @@ -308,7 +308,6 @@ language_item_table! { LangItems => Copy, sym::copy, TraitId; Clone, sym::clone, TraitId; TrivialClone, sym::trivial_clone, TraitId; - Sync, sym::sync, TraitId; DiscriminantKind, sym::discriminant_kind, TraitId; /// The associated item of the `DiscriminantKind` trait. Discriminant, sym::discriminant_type, TypeAliasId; diff --git a/tests/auxiliary/minicore.rs b/tests/auxiliary/minicore.rs index c670873a1b770..738a9548ee286 100644 --- a/tests/auxiliary/minicore.rs +++ b/tests/auxiliary/minicore.rs @@ -218,7 +218,6 @@ impl Neg for i8 { } } -#[lang = "sync"] pub trait Sync {} impl_marker_trait!( Sync => [