From 44a572e4e66d946c696d17f532171489404ffa8e Mon Sep 17 00:00:00 2001 From: JoJoJet <21144246+JoJoJet@users.noreply.github.com> Date: Fri, 3 Feb 2023 09:17:48 +0000 Subject: [PATCH] Fix ignored lifetimes in `#[derive(SystemParam)]` (#7458) # Objective Fix #7447. The `SystemParam` derive uses the wrong lifetimes for ignored fields. ## Solution Use type inference instead of explicitly naming the types of ignored fields. This allows the compiler to automatically use the correct lifetime. --- crates/bevy_ecs/macros/src/lib.rs | 2 +- crates/bevy_ecs/src/system/system_param.rs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/bevy_ecs/macros/src/lib.rs b/crates/bevy_ecs/macros/src/lib.rs index 07d01a8c870ab..d914f3488c430 100644 --- a/crates/bevy_ecs/macros/src/lib.rs +++ b/crates/bevy_ecs/macros/src/lib.rs @@ -506,7 +506,7 @@ pub fn derive_system_param(input: TokenStream) -> TokenStream { >::get_param(&mut state.state, system_meta, world, change_tick); #struct_name { #(#fields: #field_locals,)* - #(#ignored_fields: <#ignored_field_types>::default(),)* + #(#ignored_fields: std::default::Default::default(),)* } } } diff --git a/crates/bevy_ecs/src/system/system_param.rs b/crates/bevy_ecs/src/system/system_param.rs index 4dc3a85bdbf1b..c97dcf397e396 100644 --- a/crates/bevy_ecs/src/system/system_param.rs +++ b/crates/bevy_ecs/src/system/system_param.rs @@ -1541,11 +1541,12 @@ mod tests { } // Compile test for https://github.com/bevyengine/bevy/pull/6919. + // Regression test for https://github.com/bevyengine/bevy/issues/7447. #[derive(SystemParam)] - struct MyParam<'w, T: Resource, Marker: 'static> { + struct IgnoredParam<'w, T: Resource, Marker: 'static> { _foo: Res<'w, T>, #[system_param(ignore)] - marker: PhantomData, + marker: PhantomData<&'w Marker>, } // Compile tests for https://github.com/bevyengine/bevy/pull/6957.