rustbevyrapierrapier-2d

Why are Bevy's Trait bounds not satisfied for the Rapier physics plugin?


I've been trying to run this minimal example to get Rapier's physics working with Bevy:

use bevy::prelude::*;
use bevy_rapier2d::prelude::*;


fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
        .run();
}

and it's failing:

error[E0277]: the trait bound `bevy_rapier2d::plugin::RapierPhysicsPlugin: Plugin` is not satisfied
   --> src/main.rs:8:21
    |
8   |         .add_plugin(RapierPhysicsPlugin::<NoUserData>::pixels_per_meter(100.0))
    |          ---------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Plugin` is not implemented for `bevy_rapier2d::plugin::RapierPhysicsPlugin`
    |          |
    |          required by a bound introduced by this call
    |
    = help: the following other types implement trait `Plugin`:
              AnimationPlugin
              AssetCountDiagnosticsPlugin<T>
              AssetPlugin
              AudioPlugin
              BloomPlugin
              CameraPlugin
              CameraProjectionPlugin<T>
              ColorMaterialPlugin
            and 44 others
note: required by a bound in `bevy::prelude::App::add_plugin`
   --> /home/techperson/.cargo/registry/src/github.com-1ecc6299db9ec823/bevy_app-0.9.0/src/app.rs:837:12
    |
837 |         T: Plugin,
    |            ^^^^^^ required by this bound in `bevy::prelude::App::add_plugin`

For more information about this error, try `rustc --explain E0277`.

Expected behavior is what is described in the Rapier documentation.

Some info:

$ cargo version
cargo 1.66.0-beta.1 (7e484fc1a 2022-10-27)

$ rustup show
Default host: x86_64-unknown-linux-gnu
rustup home:  /home/techperson/.rustup

installed toolchains
--------------------

stable-x86_64-unknown-linux-gnu
beta-x86_64-unknown-linux-gnu (default)
nightly-x86_64-unknown-linux-gnu

active toolchain
----------------

beta-x86_64-unknown-linux-gnu (default)
rustc 1.66.0-beta.1 (e080cc5a6 2022-11-01)

Relevant part of Cargo.toml:

[dependencies]
bevy = "0.9.0"
bevy_rapier2d = "0.18.0"

I tried manually implementing the Plugin trait, but can't because its from a different crate:

error[E0117]: only traits defined in the current crate can be implemented for types defined outside of the crate
 --> src/main.rs:4:1
  |
4 | impl Plugin for RapierPhysicsPlugin {}
  | ^^^^^^^^^^^^^^^^-------------------
  | |               |
  | |               `bevy_rapier2d::plugin::RapierPhysicsPlugin` is not defined in the current crate
  | impl doesn't use only types from inside the current crate
  |
  = note: define and implement a trait or new type instead

For more information about this error, try `rustc --explain E0117`.

I've also tried the stable, beta, and nightly toolchains. beta and nightly fail with the aforementioned error, and stable fails because if-let statements aren't stable.


Solution

  • Bevy 0.9 is an extremely recent release, 3 days ago at the time of writing. It changed quite a lot about bevy internals, especially the trait system, as can be expected of an unstable project at this stage.

    Most of the ecosystem will be upgrading over the course of the next few weeks. Revert back to bevy 0.8 and you should be fine for now.