Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unsound lifetime annotation on
Query::get_component
(#2964)
#2605 changed the lifetime annotations on `get_component` introducing unsoundness as you could keep the returned borrow even after using the query. Example unsoundness: ```rust use bevy::prelude::*; fn main() { App::new() .add_startup_system(startup) .add_system(unsound) .run(); } #[derive(Debug, Component, PartialEq, Eq)] struct Foo(Vec<u32>); fn startup(mut c: Commands) { let e = c.spawn().insert(Foo(vec![10])).id(); c.insert_resource(e); } fn unsound(mut q: Query<&mut Foo>, res: Res<Entity>) { let foo = q.get_component::<Foo>(*res).unwrap(); let mut foo2 = q.iter_mut().next().unwrap(); let first_elem = &foo.0[0]; for _ in 0..16 { foo2.0.push(12); } dbg!(*first_elem); } ``` output: `[src/main.rs:26] *first_elem = 0`
- Loading branch information