Skip to content

Remove 's lifetime from WorldQuery::Fetch #19720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025

Conversation

chescock
Copy link
Contributor

Objective

Unblock #18162.

#15396 added the 's lifetime to QueryData::Item to make it possible for query items to borrow from the state. The state isn't passed directly to QueryData::fetch(), so it also added the 's lifetime to WorldQuery::Fetch so that we can pass the borrows through there.

Unfortunately, having WorldQuery::Fetch borrow from the state makes it impossible to have owned state, because we store the state and the Fetch in the same struct during iteration.

Solution

Undo the change to add the 's lifetime to WorldQuery::Fetch.

Instead, add a &'s Self::State parameter to QueryData::fetch() and QueryFilter::filter_fetch() so that borrows from the state can be passed directly to query items.

@chescock chescock added A-ECS Entities, components, systems, and events S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 18, 2025
@alice-i-cecile alice-i-cecile added this to the 0.17 milestone Jun 18, 2025
@Victoronz Victoronz added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jun 18, 2025
Co-authored-by: Emerson Coskey <emerson@coskey.dev>
@alice-i-cecile alice-i-cecile enabled auto-merge June 19, 2025 00:41
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jun 19, 2025
Merged via the queue into bevyengine:main with commit d0550f5 Jun 19, 2025
32 checks passed
Trashtalk217 pushed a commit to Trashtalk217/bevy that referenced this pull request Jul 10, 2025
# Objective

Unblock bevyengine#18162.

bevyengine#15396 added the `'s` lifetime to `QueryData::Item` to make it possible
for query items to borrow from the state. The state isn't passed
directly to `QueryData::fetch()`, so it also added the `'s` lifetime to
`WorldQuery::Fetch` so that we can pass the borrows through there.

Unfortunately, having `WorldQuery::Fetch` borrow from the state makes it
impossible to have owned state, because we store the state and the
`Fetch` in the same `struct` during iteration.

## Solution

Undo the change to add the `'s` lifetime to `WorldQuery::Fetch`.

Instead, add a `&'s Self::State` parameter to `QueryData::fetch()` and
`QueryFilter::filter_fetch()` so that borrows from the state can be
passed directly to query items.

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
Co-authored-by: Emerson Coskey <emerson@coskey.dev>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ECS Entities, components, systems, and events S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants