Skip to content

Commit

Permalink
Relax more Sync bounds on Local (bevyengine#9589)
Browse files Browse the repository at this point in the history
# Objective

bevyengine#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.
  • Loading branch information
JoJoJet authored and Ray Redondo committed Jan 9, 2024
1 parent 813971c commit 6ae557f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions crates/bevy_ecs/src/system/system_param.rs
Expand Up @@ -685,7 +685,7 @@ pub struct Local<'s, T: FromWorld + Send + 'static>(pub(crate) &'s mut T);
// SAFETY: Local only accesses internal state
unsafe impl<'s, T: FromWorld + Send + 'static> ReadOnlySystemParam for Local<'s, T> {}

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

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

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

// Compile test for https://github.com/bevyengine/bevy/pull/2838.
#[test]
Expand Down Expand Up @@ -1726,4 +1726,17 @@ mod tests {
fn my_system(_: InvariantParam) {}
assert_is_system(my_system);
}

// Compile test for https://github.com/bevyengine/bevy/pull/9589.
#[test]
fn non_sync_local() {
fn non_sync_system(cell: Local<RefCell<u8>>) {
assert_eq!(*cell.borrow(), 0);
}

let mut world = World::new();
let mut schedule = crate::schedule::Schedule::new();
schedule.add_systems(non_sync_system);
schedule.run(&mut world);
}
}

0 comments on commit 6ae557f

Please sign in to comment.