Skip to content

Commit 7be43aa

Browse files
committed
Add rustc_on_unimplemented on Sync for cell types
Suggest using a lock instead.
1 parent 0a5e500 commit 7be43aa

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

core/src/marker.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,62 @@ pub macro Copy($item:item) {
469469
#[cfg_attr(not(test), rustc_diagnostic_item = "Sync")]
470470
#[lang = "sync"]
471471
#[rustc_on_unimplemented(
472+
on(
473+
_Self = "std::cell::OnceCell<T>",
474+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::OnceLock` instead"
475+
),
476+
on(
477+
_Self = "std::cell::Cell<u8>",
478+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU8` instead",
479+
),
480+
on(
481+
_Self = "std::cell::Cell<u16>",
482+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU16` instead",
483+
),
484+
on(
485+
_Self = "std::cell::Cell<u32>",
486+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU32` instead",
487+
),
488+
on(
489+
_Self = "std::cell::Cell<u64>",
490+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicU64` instead",
491+
),
492+
on(
493+
_Self = "std::cell::Cell<usize>",
494+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicUsize` instead",
495+
),
496+
on(
497+
_Self = "std::cell::Cell<i8>",
498+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI8` instead",
499+
),
500+
on(
501+
_Self = "std::cell::Cell<i16>",
502+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI16` instead",
503+
),
504+
on(
505+
_Self = "std::cell::Cell<i32>",
506+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI32` instead",
507+
),
508+
on(
509+
_Self = "std::cell::Cell<i64>",
510+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicI64` instead",
511+
),
512+
on(
513+
_Self = "std::cell::Cell<isize>",
514+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicIsize` instead",
515+
),
516+
on(
517+
_Self = "std::cell::Cell<bool>",
518+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` or `std::sync::atomic::AtomicBool` instead",
519+
),
520+
on(
521+
_Self = "std::cell::Cell<T>",
522+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock`",
523+
),
524+
on(
525+
_Self = "std::cell::RefCell<T>",
526+
note = "if you want to do aliasing and mutation between multiple threads, use `std::sync::RwLock` instead",
527+
),
472528
message = "`{Self}` cannot be shared between threads safely",
473529
label = "`{Self}` cannot be shared between threads safely"
474530
)]

0 commit comments

Comments
 (0)