Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid lifetime when deriving SystemParam #7447

Closed
BeastLe9enD opened this issue Jan 31, 2023 · 2 comments
Closed

Invalid lifetime when deriving SystemParam #7447

BeastLe9enD opened this issue Jan 31, 2023 · 2 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation
Milestone

Comments

@BeastLe9enD
Copy link
Contributor

Bevy Version

The latest version on github (a441939)

I am getting a problem when using #[derive(SystemParam)]. My structure is the following :

#[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 ()>,
}

In my opinion this is valid, but the compiler complains:

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 expanded the macro using cargo expand.

...
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(),
            }
        }
...

As the error already says, a structure with the lifetime 's is returned, but the function has a return type with the lifetime 's2.
I don't know if the error only occurs because I'm using something incorrectly, but even if I am, I don't really find the error message accurate.

@BeastLe9enD BeastLe9enD added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 31, 2023
@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Docs An addition or correction to our documentation and removed S-Needs-Triage This issue needs to be labelled labels Jan 31, 2023
@alice-i-cecile
Copy link
Member

What happens if you replace 'w, 's with 'static, 'static?

@BeastLe9enD
Copy link
Contributor Author

What happens if you replace 'w, 's with 'static, 'static?

It does not work, because the proc macro only accepts lifetimes named 'w and 's

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior C-Docs An addition or correction to our documentation
Projects
None yet
2 participants