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

Creating a bundle complains about mem::forget #4601

Closed
SUPERCILEX opened this issue Apr 26, 2022 · 6 comments
Closed

Creating a bundle complains about mem::forget #4601

SUPERCILEX opened this issue Apr 26, 2022 · 6 comments
Labels
A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change

Comments

@SUPERCILEX
Copy link
Contributor

Bevy version

0.7.0

What you did

#[derive(Component, Default)]
pub struct NominoMarker;

#[derive(Component, Deref)]
pub struct BoundingBoxes(&'static [Rect<f32>]);

#[derive(Bundle)]
pub struct NominoBundle {
    #[bundle]
    shape: bevy_prototype_lyon::entity::ShapeBundle,
    bounding_boxes: BoundingBoxes,
    _marker: NominoMarker,
}

What you expected to happen

No warnings

What actually happened

warning: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it
   --> src/nominos.rs:106:10
    |
106 | #[derive(Bundle)]
    |          ^^^^^^
    |
    = note: `#[warn(clippy::forget_non_drop)]` on by default
note: argument has type `nominos::BoundingBoxes`
   --> src/nominos.rs:106:10
    |
106 | #[derive(Bundle)]
    |          ^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#forget_non_drop
    = note: this warning originates in the derive macro `Bundle` (in Nightly builds, run with -Z macro-backtrace for more info)
@SUPERCILEX SUPERCILEX added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 26, 2022
@alice-i-cecile
Copy link
Member

Are you on Rust nightly? Can you reproduce this with a simpler bundle?

@alice-i-cecile alice-i-cecile added A-ECS Entities, components, systems, and events C-Code-Quality A section of code that is hard to understand or change and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 26, 2022
@SUPERCILEX
Copy link
Contributor Author

SUPERCILEX commented Apr 26, 2022

Yeah: rustc 1.62.0-nightly (18f314e70 2022-04-24). Simpler:

#[derive(Component, Default)]
pub struct NominoMarker;

#[derive(Bundle)]
pub struct TestBundle {
    _marker: NominoMarker,
}

@DJMcNab
Copy link
Member

DJMcNab commented Apr 26, 2022

The std::mem::forget version of the bundle code is slightly suspect anyway; we need to migrate it to MaybeUninit (maybe ManuallyDrop is sufficient). (I suspect there are at least 2 open PRs which make this change.)

A temporary workaround is just to allow that lint for your entire crate.

@SUPERCILEX
Copy link
Contributor Author

Seems like these two: #3634 and #2975

@alice-i-cecile alice-i-cecile added this to the Bevy 0.8 milestone May 1, 2022
@alice-i-cecile
Copy link
Member

Running into this on nightly too for my own projects, which breaks my clippy-checking CI. For those looking for a workaround, add #![allow(clippy::forget_non_drop)] to the top of your main.rs to silence the warning for now.

Indy2222 added a commit to DigitalExtinction/Game that referenced this issue Jul 1, 2022
We started to get a Clippy error in CI:

error: call to `std::mem::forget` with a value that does not implement `Drop`. Forgetting such a type is the same as dropping it
  --> crates/spawner/src/spawner.rs:19:10
   |
19 | #[derive(Bundle)]
   |          ^^^^^^
   |
   = note: `-D clippy::forget-non-drop` implied by `-D warnings`
note: argument has type `spawner::Spawn`
  --> crates/spawner/src/spawner.rs:19:10
   |
19 | #[derive(Bundle)]
   |          ^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#forget_non_drop
   = note: this error originates in the derive macro `Bundle` (in Nightly builds, run with -Z macro-backtrace for more info)

The failing lint was recently added in
rust-lang/rust-clippy#8630. Unfortunately, it is
not possible to disable linting of code generated by external macros
rust-lang/rust-clippy#407.

The issues on Bevy site is tracked here
bevyengine/bevy#4601
Shatur added a commit to gardum-game/gardum that referenced this issue Jul 3, 2022
@alice-i-cecile alice-i-cecile removed this from the Bevy 0.8 milestone Jul 18, 2022
@ghost
Copy link

ghost commented Jul 25, 2022

This problem seems to be fixed in main by #3001 because of the removal of the std::mem::forget call in bevy_ecs/src/bundle.rs (see https://github.com/bevyengine/bevy/pull/3001/files#diff-0e94997025571f709abd7cac97f03bb4e8ec8bf29650068a7e5ec07170011892L121-R126).

This code generates a warning when running cargo clippy with bevy 0.7but doesn't in bevy main:

use bevy::prelude::*;

#[derive(Bundle)]
pub struct Foo {
    bar: Bar,
}

#[derive(Component)]
struct Bar;

fn main() {}

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-Code-Quality A section of code that is hard to understand or change
Projects
None yet
Development

No branches or pull requests

3 participants