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

Plugin implementations with generic parameters can't call app.add_plugins on other plugins with generic parameters #11550

Closed
NoahShomette opened this issue Jan 26, 2024 · 5 comments
Labels
A-App Bevy apps and plugins C-Bug An unexpected or incorrect behavior

Comments

@NoahShomette
Copy link
Contributor

NoahShomette commented Jan 26, 2024

Bevy version

0.12.1

What you did

Plugin implementations with generic parameters can't call app.add_plugins on other plugins with generic parameters. This worked in 0.11 however it no longer works as of 0.12.1

Note that if you implement a trait with generic bounds and attempt to implement that trait on App then you will run into the same issue.

Minimum reproduction

Plugin version

trait SubPluginTrait: Sync + Send + 'static {}

struct MainPlugin<A: SubPluginTrait> {
    a: PhantomData<A>,
}

impl<A: SubPluginTrait + Default> Plugin for MainPlugin<A> {
    fn build(&self, app: &mut bevy::prelude::App) {
        app.add_plugins(SubPlugin::<A>::default()); // Error appears here
    }
}

#[derive(Default)]
struct SubPlugin<A: SubPluginTrait + Default> {
    a: PhantomData<A>,
}

Trait version

trait ImplementedOnApp<A: SubPluginTrait + Default>{
    fn do_something_with_app(&mut self);
}

impl<A: SubPluginTrait + Default> ImplementedOnApp<A> for App{
    fn do_something_with_app(&mut self) {
        self.add_plugins(GenericPlugin2::<A>::default()); // Error appears here
    }
}

The error that is returned is:


error[E0277]: the trait bound `SubPlugin<A>: bevy_app::plugin::sealed::Plugins<_>` is not satisfied
   --> crates/client/client_binary/src/controls/testing.rs:13:25
    |
13  |         app.add_plugins(SubPlugin::<A>::default());
    |             ----------- ^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `bevy_app::plugin::sealed::Plugins<_>` is not implemented for `SubPlugin<A>`
    |             |
    |             required by a bound introduced by this call
    |
    = help: the following other types implement trait `bevy_app::plugin::sealed::Plugins<Marker>`:
              <() as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker,)>>
              <(S0,) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0)>>
              <(S0, S1) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1)>>
              <(S0, S1, S2) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1, P2)>>
              <(S0, S1, S2, S3) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1, P2, P3)>>
              <(S0, S1, S2, S3, S4) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1, P2, P3, P4)>>
              <(S0, S1, S2, S3, S4, S5) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1, P2, P3, P4, P5)>>
              <(S0, S1, S2, S3, S4, S5, S6) as bevy_app::plugin::sealed::Plugins<(bevy_app::plugin::sealed::PluginsTupleMarker, P0, P1, P2, P3, P4, P5, P6)>>
            and 8 others
    = note: required for `SubPlugin<A>` to implement `Plugins<_>`
note: required by a bound in `App::add_plugins`
   --> /home/noahs/.cargo/registry/src/index.crates.io-6f17d22bba15001f/bevy_app-0.12.1/src/app.rs:721:52
    |
721 |     pub fn add_plugins<M>(&mut self, plugins: impl Plugins<M>) -> &mut Self {
    |                                                    ^^^^^^^^^^ required by this bound in `App::add_plugins`

@NoahShomette NoahShomette added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 26, 2024
@alice-i-cecile alice-i-cecile added A-App Bevy apps and plugins and removed S-Needs-Triage This issue needs to be labelled labels Jan 26, 2024
@alice-i-cecile
Copy link
Member

Can you reproduce it on main? What if you use the new style on the #11080 branch?

@NoahShomette
Copy link
Contributor Author

Can you reproduce it on main? What if you use the new style on the #11080 branch?

Yes to both of these. Its still broken in main and on the branch

@alice-i-cecile
Copy link
Member

Great. That's about what what I expected, but it's very helpful to have confirmation.

@NoahShomette
Copy link
Contributor Author

Great. That's about what what I expected, but it's very helpful to have confirmation.

Hmm super weird but if I try it now on the 0.11 version of Bevy it no longer works. It 100% worked on my project back then though, I definitely used it lol. Rust issue...?

@NoahShomette
Copy link
Contributor Author

NoahShomette commented Jan 26, 2024

Nevermind. I messed up on this one. Reproduction is wrong but same error. Error was originally that Leafwing added new TypePath bounds to their generic umbrella implementation of plugin for their struct and I copy pasted old code that didn't satisfy the new bounds and it led me on a rabbit hole. Plugin works great still :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-App Bevy apps and plugins C-Bug An unexpected or incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants