mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Fix world borrow for DeferredWorld::query (#14744)
# Objective As is, calling [`DeferredWorld::query`](https://docs.rs/bevy/latest/bevy/ecs/world/struct.DeferredWorld.html#method.query) requires you to first `reborrow()` the world in order to use it at all. Simple reproduction: ```rust fn test<'w>(mut world: DeferredWorld<'w>, mut state: QueryState<(), ()>) { let query = world.query(&mut state); // let query = world.reborrow().query(&mut state); // << Required } ``` Error message: ``` error[E0597]: `world` does not live long enough | 444 | fn test<'w>(mut world: DeferredWorld<'w>, mut state: QueryState<(), ()>) { | -- --------- binding `world` declared here | | | lifetime `'w` defined here 445 | let query = world.query(&mut state); | ^^^^^------------------ | | | borrowed value does not live long enough | argument requires that `world` is borrowed for `'w` 446 | } | - `world` dropped here while still borrowed ``` ## Solution Fix the world borrow lifetime on the `query` method, which now correctly allows the above usage.
This commit is contained in:
parent
a34651502c
commit
7d3068e6c3
1 changed files with 2 additions and 2 deletions
|
@ -119,9 +119,9 @@ impl<'w> DeferredWorld<'w> {
|
|||
/// If state is from a different world then self
|
||||
#[inline]
|
||||
pub fn query<'s, D: QueryData, F: QueryFilter>(
|
||||
&'w mut self,
|
||||
&mut self,
|
||||
state: &'s mut QueryState<D, F>,
|
||||
) -> Query<'w, 's, D, F> {
|
||||
) -> Query<'_, 's, D, F> {
|
||||
state.validate_world(self.world.id());
|
||||
state.update_archetypes(self);
|
||||
// SAFETY: We ran validate_world to ensure our state matches
|
||||
|
|
Loading…
Reference in a new issue