#SystemParam lifetime issues

1 messages · Page 1 of 1 (latest)

outer tangle
#

Hey, I'm having some troubles with #[derive(SystemParam)]

#[derive(SystemParam)]
pub struct InputResources<'w, 's> {
    pub keyboard_input: Res<'w, Input<KeyCode>>,
    pub egui_input: ResMut<'w, EguiRenderInputContainer>,
    #[system_param(ignore)]
    _marker: PhantomData<&'s ()>,
}

It complains that the lifetime must not live long enough

error: lifetime may not live long enough
  --> crates\kamel-egui\src\systems.rs:56:10
   |
56 | #[derive(SystemParam)]
   |          ^^^^^^^^^^^
   |          |
   |          lifetime `'s` defined here
   |          lifetime `'s2` defined here
   |          associated function was supposed to return data with lifetime `'s2` but it is returning data with lifetime `'s`
   |
   = help: consider adding the following bound: `'s: 's2`
   = note: this error originates in the derive macro `SystemParam` (in Nightly builds, run with -Z macro-backtrace for more info)

I don't get where the lifetime s2 comes from.... Any ideas?

austere hornet
#

It might be that the derive is expecting the lifetimes in a specific order <'w, 's>

outer tangle
#

Yes, I tried both, but still not working. Im not sure where the s2 comes from, as the proc macro validates all lifetimes and ensures that they are named w or s

river veldt
#

try using cargo expand

outer tangle
#

good point

#
pub struct InputResources<'s, 'w> {
    pub keyboard_input: Res<'w, Input<KeyCode>>,
    pub egui_input: ResMut<'w, EguiRenderInputContainer>,
    #[system_param(ignore)]
    _marker: PhantomData<&'s ()>,
}
const _: () = {
    #[doc(hidden)]
    pub struct FetchState<'w, 's> {
        state: (
            <Res<'w, Input<KeyCode>> as bevy_ecs::system::SystemParam>::State,
            <ResMut<
                'w,
                EguiRenderInputContainer,
            > as bevy_ecs::system::SystemParam>::State,
        ),
        marker: std::marker::PhantomData<
            (
                <bevy_ecs::prelude::Query<
                    'w,
                    's,
                    (),
                > as bevy_ecs::system::SystemParam>::State,
                fn() -> PhantomData<&'s ()>,
            ),
        >,
    }
#
unsafe impl<'w, 's> bevy_ecs::system::SystemParam for InputResources<'s, 'w> {
        type State = FetchState<'static, 'static>;
        type Item<'_w, '_s> = InputResources<'_s, '_w>;
        fn init_state(
            world: &mut bevy_ecs::world::World,
            system_meta: &mut bevy_ecs::system::SystemMeta,
        ) -> Self::State {
            FetchState {
                state: <(
                    Res<'w, Input<KeyCode>>,
                    ResMut<'w, EguiRenderInputContainer>,
                ) as bevy_ecs::system::SystemParam>::init_state(world, system_meta),
                marker: std::marker::PhantomData,
            }
        }
        fn new_archetype(
            state: &mut Self::State,
            archetype: &bevy_ecs::archetype::Archetype,
            system_meta: &mut bevy_ecs::system::SystemMeta,
        ) {
            <(
                Res<'w, Input<KeyCode>>,
                ResMut<'w, EguiRenderInputContainer>,
            ) as bevy_ecs::system::SystemParam>::new_archetype(
                &mut state.state,
                archetype,
                system_meta,
            )
        }
#
        fn apply(
            state: &mut Self::State,
            system_meta: &bevy_ecs::system::SystemMeta,
            world: &mut bevy_ecs::world::World,
        ) {
            <(
                Res<'w, Input<KeyCode>>,
                ResMut<'w, EguiRenderInputContainer>,
            ) as bevy_ecs::system::SystemParam>::apply(
                &mut state.state,
                system_meta,
                world,
            );
        }
        unsafe fn get_param<'w2, 's2>(
            state: &'s2 mut Self::State,
            system_meta: &bevy_ecs::system::SystemMeta,
            world: &'w2 bevy_ecs::world::World,
            change_tick: u32,
        ) -> Self::Item<'w2, 's2> {
            let (f0, f1) = <(
                Res<'w, Input<KeyCode>>,
                ResMut<'w, EguiRenderInputContainer>,
            ) as bevy_ecs::system::SystemParam>::get_param(
                &mut state.state,
                system_meta,
                world,
                change_tick,
            );
            InputResources {
                keyboard_input: f0,
                egui_input: f1,
                _marker: <PhantomData<&'s ()>>::default(),
            }
        }
    }
    unsafe impl<'w, 's> bevy_ecs::system::ReadOnlySystemParam
    for InputResources<'s, 'w>
    where
        Res<'w, Input<KeyCode>>: bevy_ecs::system::ReadOnlySystemParam,
        ResMut<'w, EguiRenderInputContainer>: bevy_ecs::system::ReadOnlySystemParam,
    {}
};
#

the get_param is the only place where a `w2 appears, but there is no relation between w and w2, s2 and s. Is this a bug or am I using the proc macro wrong?

#

Im using the newest version on git btw

river veldt
#

pub struct InputResources<'s, 'w> { is this what it actually looks like in your code? what happens if you switch 'w and 's ?

outer tangle
#

If I switch them, the same error appears

outer tangle
#

I think I'll make an issue on github, because It does not look like its my mistake (at least I don't think it is at this point). And if its my mistake, there should be a better description what actually went wrong.

#

thanks for your help 🙂