diff --git a/crates/bevy_ecs/src/system/mod.rs b/crates/bevy_ecs/src/system/mod.rs index 8f0172af97a59..d4fd0ad79909c 100644 --- a/crates/bevy_ecs/src/system/mod.rs +++ b/crates/bevy_ecs/src/system/mod.rs @@ -27,8 +27,8 @@ mod tests { query::{Added, Changed, Or, QueryState, With, Without}, schedule::{Schedule, Stage, SystemStage}, system::{ - ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, Query, QuerySet, - RemovedComponents, Res, ResMut, System, SystemState, + ConfigurableSystem, IntoExclusiveSystem, IntoSystem, Local, NonSend, NonSendMut, Query, + QuerySet, RemovedComponents, Res, ResMut, System, SystemState, }, world::{FromWorld, World}, }; @@ -331,6 +331,48 @@ mod tests { assert!(*world.get_resource::().unwrap()); } + #[test] + fn non_send_option_system() { + let mut world = World::default(); + + world.insert_resource(false); + struct NotSend1(std::rc::Rc); + struct NotSend2(std::rc::Rc); + world.insert_non_send(NotSend1(std::rc::Rc::new(0))); + + fn sys( + op: Option>, + mut _op2: Option>, + mut run: ResMut, + ) { + op.expect("NonSend should exist"); + *run = true; + } + + run_system(&mut world, sys); + // ensure the system actually ran + assert!(*world.get_resource::().unwrap()); + } + + #[test] + fn non_send_system() { + let mut world = World::default(); + + world.insert_resource(false); + struct NotSend1(std::rc::Rc); + struct NotSend2(std::rc::Rc); + + world.insert_non_send(NotSend1(std::rc::Rc::new(1))); + world.insert_non_send(NotSend2(std::rc::Rc::new(2))); + + fn sys(_op: NonSend, mut _op2: NonSendMut, mut run: ResMut) { + *run = true; + } + + run_system(&mut world, sys); + assert!(*world.get_resource::().unwrap()); + } + #[test] fn remove_tracking() { let mut world = World::new(); diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 2b496e9e63355..5c6693b1ab9e9 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -817,7 +817,7 @@ impl<'w, 's, T: 'static> SystemParamFetch<'w, 's> for NonSendState { /// The [`SystemParamState`] of `Option>`. pub struct OptionNonSendState(NonSendState); -impl<'w, T: Component> SystemParam for Option> { +impl<'w, T: 'static> SystemParam for Option> { type Fetch = OptionNonSendState; } @@ -874,7 +874,7 @@ unsafe impl SystemParamState for NonSendMutState { fn init(world: &mut World, system_meta: &mut SystemMeta, _config: Self::Config) -> Self { system_meta.set_non_send(); - let component_id = world.components.get_or_insert_non_send_resource_id::(); + let component_id = world.initialize_non_send_resource::(); let combined_access = system_meta.component_access_set.combined_access_mut(); if combined_access.has_write(component_id) { panic!(