bevy/crates
Boxy 024d98457c yeet unsound lifetime annotations on Query methods (#4243)
# Objective
Continuation of #2964 (I really should have checked other methods when I made that PR)

yeet unsound lifetime annotations on `Query` methods.
Example unsoundness:
```rust
use bevy::prelude::*;

fn main() {
    App::new().add_startup_system(bar).add_system(foo).run();
}

pub fn bar(mut cmds: Commands) {
    let e = cmds.spawn().insert(Foo { a: 10 }).id();
    cmds.insert_resource(e);
}

#[derive(Component, Debug, PartialEq, Eq)]
pub struct Foo {
    a: u32,
}
pub fn foo(mut query: Query<&mut Foo>, e: Res<Entity>) {
    dbg!("hi");
    {
        let data: &Foo = query.get(*e).unwrap();
        let data2: Mut<Foo> = query.get_mut(*e).unwrap();
        assert_eq!(data, &*data2); // oops UB
    }

    {
        let data: &Foo = query.single();
        let data2: Mut<Foo> = query.single_mut();
        assert_eq!(data, &*data2); // oops UB
    }

    {
        let data: &Foo = query.get_single().unwrap();
        let data2: Mut<Foo> = query.get_single_mut().unwrap();
        assert_eq!(data, &*data2); // oops UB
    }

    {
        let data: &Foo = query.iter().next().unwrap();
        let data2: Mut<Foo> = query.iter_mut().next().unwrap();
        assert_eq!(data, &*data2); // oops UB
    }

    {
        let mut opt_data: Option<&Foo> = None;
        let mut opt_data_2: Option<Mut<Foo>> = None;
        query.for_each(|data| opt_data = Some(data));
        query.for_each_mut(|data| opt_data_2 = Some(data));
        assert_eq!(opt_data.unwrap(), &*opt_data_2.unwrap()); // oops UB
    }
    dbg!("bye");
}

```

## Solution
yeet unsound lifetime annotations on `Query` methods

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
2022-03-22 02:49:41 +00:00
..
bevy_app Prevent event from getting registered twice (#4258) 2022-03-20 21:54:10 +00:00
bevy_asset Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_audio Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_core Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_core_pipeline Tracy spans around main 3D passes (#4182) 2022-03-19 12:57:47 +00:00
bevy_crevice Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_derive Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_diagnostic Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_dylib Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_dynamic_plugin Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_ecs yeet unsound lifetime annotations on Query methods (#4243) 2022-03-22 02:49:41 +00:00
bevy_ecs_compile_fail_tests yeet unsound lifetime annotations on Query methods (#4243) 2022-03-22 02:49:41 +00:00
bevy_gilrs Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_gltf Gltf animations (#3751) 2022-03-22 02:26:34 +00:00
bevy_hierarchy Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_input Check an Input's pressed set before adding to just_released. (#4209) 2022-03-20 21:54:09 +00:00
bevy_internal Tracy spans around main 3D passes (#4182) 2022-03-19 12:57:47 +00:00
bevy_log Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_macro_utils Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_math Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_pbr yeet unsound lifetime annotations on Query methods (#4243) 2022-03-22 02:49:41 +00:00
bevy_reflect Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_render bevy_render: Support removal of nodes, edges, subgraphs (#3048) 2022-03-21 23:58:37 +00:00
bevy_scene Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_sprite yeet unsound lifetime annotations on Query methods (#4243) 2022-03-22 02:49:41 +00:00
bevy_tasks Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_text Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_transform Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_ui Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_utils Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_window Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00
bevy_winit Bump Bevy to 0.7.0-dev (#4230) 2022-03-19 03:54:15 +00:00