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

[0.5] Deriving Bundle doesn't work if using where clauses #1777

Closed
concave-sphere opened this issue Mar 28, 2021 · 0 comments
Closed

[0.5] Deriving Bundle doesn't work if using where clauses #1777

concave-sphere opened this issue Mar 28, 2021 · 0 comments
Labels
A-ECS Entities, components, systems, and events C-Bug An unexpected or incorrect behavior

Comments

@concave-sphere
Copy link

Bevy version

94c4184

Operating system & version

Debian GNU/Linux 10.8 "buster"

What you did

I used the bevy::ecs::bundle::Bundle derive macro with a struct that used a where macro. Example code below and in test.tar.gz.

#[cfg(feature = "broken")]
#[derive(bevy::ecs::bundle::Bundle)]
struct Test<T>
where
    T: bevy::ecs::component::Component,
{
    i: T,
}

#[cfg(feature = "working")]
#[derive(bevy::ecs::bundle::Bundle)]
struct Test<T: bevy::ecs::component::Component> {
    i: T,
}

fn main() {
    let t = Test { i: 10 };
    println!("hello world, {}", t.i);
}


What you expected to happen

Both versions of this code should compile. It shouldn't matter whether I declare a type bound in the brackets or in a where clause.

What actually happened

The code listed under working compiles without problems. But the code listed under broken fails to compile with many copies of this error:

error[E0277]: `T` cannot be shared between threads safely
  --> src/main.rs:2:10
   |
2  | #[derive(bevy::ecs::bundle::Bundle)]
   |          ^^^^^^^^^^^^^^^^^^^^^^^^^ `T` cannot be shared between threads safely
   | 
  ::: /home/daniel/.cargo/git/checkouts/bevy-f7ffde730c324c74/94c4184/crates/bevy_ecs/src/bundle.rs:45:33
   |
45 | pub unsafe trait Bundle: Send + Sync + 'static {
   |                                 ---- required by this bound in `Bundle`
   |
   = note: required because it appears within the type `Test<T>`
   = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider restricting type parameter `T`
   |
3  | struct Test<T: Sync>
   |              ^^^^^^

Additional information

This seems to apply to any type bound required by the struct -- bounds that were living happily in the where clause before I tried to derive Bundle are suddenly reported as "not implemented", with an error pointing at the where clause that ought to make them available. Not only is this annoying, it doesn't seem to be possible to declare bounds on associated types anywhere but in the where clause, so working around the problem would require restructuring a number of my type declarations.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-ECS Entities, components, systems, and events labels Mar 28, 2021
@bors bors bot closed this as completed in 3e285d5 Apr 3, 2021
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants