Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix soundness of
UnsafeWorldCell
usage example (bevyengine#10941)
# Objective - The example in the docs is unsound. Demo: ```rust #[derive(Resource)] struct MyRes(u32); fn main() { let mut w = World::new(); w.insert_resource(MyRes(0)); let (mut res, comp) = split_world_access(&mut w); let mut r1 = res.get_resource_mut::<MyRes>().unwrap(); let mut r2 = res.get_resource_mut::<MyRes>().unwrap(); *r1 = MyRes(1); *r2 = MyRes(2); } ``` The API in the example allows aliasing mutable references to the same resource. Miri also complains when running this. ## Solution - Change the example API to make the returned `Mut` borrow from the `OnlyResourceAccessWorld` instead of borrowing from the world via `'w`. This prevents obtaining more than one `Mut` at the same time from it.
- Loading branch information