Skip to content

Commit da8ab16

Browse files
authored
Relax more Sync bounds on Local (#9589)
# Objective #5483 allows for the creation of non-`Sync` locals. However, it's not actually possible to use these types as there is a `Sync` bound on the `Deref` impls. ## Solution Remove the unnecessary bounds.
1 parent 4e59671 commit da8ab16

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

crates/bevy_ecs/src/system/system_param.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ pub struct Local<'s, T: FromWorld + Send + 'static>(pub(crate) &'s mut T);
685685
// SAFETY: Local only accesses internal state
686686
unsafe impl<'s, T: FromWorld + Send + 'static> ReadOnlySystemParam for Local<'s, T> {}
687687

688-
impl<'s, T: FromWorld + Send + Sync + 'static> Deref for Local<'s, T> {
688+
impl<'s, T: FromWorld + Send + 'static> Deref for Local<'s, T> {
689689
type Target = T;
690690

691691
#[inline]
@@ -694,7 +694,7 @@ impl<'s, T: FromWorld + Send + Sync + 'static> Deref for Local<'s, T> {
694694
}
695695
}
696696

697-
impl<'s, T: FromWorld + Send + Sync + 'static> DerefMut for Local<'s, T> {
697+
impl<'s, T: FromWorld + Send + 'static> DerefMut for Local<'s, T> {
698698
#[inline]
699699
fn deref_mut(&mut self) -> &mut Self::Target {
700700
self.0
@@ -1560,7 +1560,7 @@ mod tests {
15601560
query::{ReadOnlyWorldQuery, WorldQuery},
15611561
system::{assert_is_system, Query},
15621562
};
1563-
use std::marker::PhantomData;
1563+
use std::{cell::RefCell, marker::PhantomData};
15641564

15651565
// Compile test for https://github.com/bevyengine/bevy/pull/2838.
15661566
#[test]
@@ -1726,4 +1726,17 @@ mod tests {
17261726
fn my_system(_: InvariantParam) {}
17271727
assert_is_system(my_system);
17281728
}
1729+
1730+
// Compile test for https://github.com/bevyengine/bevy/pull/9589.
1731+
#[test]
1732+
fn non_sync_local() {
1733+
fn non_sync_system(cell: Local<RefCell<u8>>) {
1734+
assert_eq!(*cell.borrow(), 0);
1735+
}
1736+
1737+
let mut world = World::new();
1738+
let mut schedule = crate::schedule::Schedule::new();
1739+
schedule.add_systems(non_sync_system);
1740+
schedule.run(&mut world);
1741+
}
17291742
}

0 commit comments

Comments
 (0)