rt: Scoped should not be Sync (#5765)

If the `Scoped` type is `Sync`, then you can call `set` from two threads in parallel. Since it accesses `inner` without synchronization, this is a data race.

This is a soundness issue for the `Scoped` type, but since this is an internal API and we don't use it incorrectly anywhere, no harm is done.
This commit is contained in:
Alice Ryhl
2023-06-05 09:36:48 -07:00
committed by GitHub
parent 076d77c186
commit 15712018da
+1 -3
View File
@@ -6,8 +6,6 @@ pub(super) struct Scoped<T> {
pub(super) inner: Cell<*const T>,
}
unsafe impl<T> Sync for Scoped<T> {}
impl<T> Scoped<T> {
pub(super) const fn new() -> Scoped<T> {
Scoped {
@@ -52,7 +50,7 @@ impl<T> Scoped<T> {
if val.is_null() {
f(None)
} else {
unsafe { f(Some(&*(val as *const T))) }
unsafe { f(Some(&*val)) }
}
}
}