Skip to content

Commit

Permalink
Add mutual exclusion safety info on filter_fetch (bevyengine#9836)
Browse files Browse the repository at this point in the history
# Objective

Currently, in bevy, it's valid to do `Query<&mut Foo, Changed<Foo>>`.

This assumes that `filter_fetch` and `fetch` are mutually exclusive,
because of the mutable reference to the tick that `Mut<Foo>` implies and
the reference that `Changed<Foo>` implies. However nothing guarantees
that.

## Solution

Documenting this assumption as a safety invariant is the least thing.
  • Loading branch information
nicopap authored Sep 19, 2023
1 parent 41a35ff commit 9e52697
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/bevy_ecs/src/query/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,9 @@ pub unsafe trait WorldQuery {
///
/// Must always be called _after_ [`WorldQuery::set_table`] or [`WorldQuery::set_archetype`]. `entity` and
/// `table_row` must be in the range of the current table and archetype.
///
/// If this includes any mutable access, then this should never be called
/// while the return value of [`WorldQuery::fetch`] for the same entity is live.
#[allow(unused_variables)]
#[inline(always)]
unsafe fn filter_fetch(
Expand Down

0 comments on commit 9e52697

Please sign in to comment.