Skip to content

Commit 7d3068e

Browse files
authored
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.
1 parent a346515 commit 7d3068e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

crates/bevy_ecs/src/world/deferred_world.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ impl<'w> DeferredWorld<'w> {
119119
/// If state is from a different world then self
120120
#[inline]
121121
pub fn query<'s, D: QueryData, F: QueryFilter>(
122-
&'w mut self,
122+
&mut self,
123123
state: &'s mut QueryState<D, F>,
124-
) -> Query<'w, 's, D, F> {
124+
) -> Query<'_, 's, D, F> {
125125
state.validate_world(self.world.id());
126126
state.update_archetypes(self);
127127
// SAFETY: We ran validate_world to ensure our state matches

0 commit comments

Comments
 (0)