bevy/crates/bevy_sprite/src
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
..
mesh2d yeet unsound lifetime annotations on Query methods (#4243) 2022-03-22 02:49:41 +00:00
render Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
bundle.rs Add 2d meshes and materials (#3460) 2022-01-08 01:29:08 +00:00
collide_aabb.rs Add the Inside version to the Collision enum (#2489) 2022-02-01 22:40:25 +00:00
dynamic_texture_atlas_builder.rs Replace old renderer with new renderer (#3312) 2021-12-14 03:58:23 +00:00
lib.rs Make get_resource (and friends) infallible (#4047) 2022-02-27 22:37:18 +00:00
rect.rs Implement the Overflow::Hidden style property for UI (#3296) 2021-12-19 05:44:28 +00:00
sprite.rs only use unique type UUIDs (#3579) 2022-02-12 19:58:02 +00:00
texture_atlas.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00
texture_atlas_builder.rs small and mostly pointless refactoring (#2934) 2022-02-13 22:33:55 +00:00