From 9e52697572bd856de070fe4faad830d54d7ac0d8 Mon Sep 17 00:00:00 2001 From: Nicola Papale Date: Tue, 19 Sep 2023 23:49:33 +0200 Subject: [PATCH] Add mutual exclusion safety info on filter_fetch (#9836) # Objective Currently, in bevy, it's valid to do `Query<&mut Foo, Changed>`. This assumes that `filter_fetch` and `fetch` are mutually exclusive, because of the mutable reference to the tick that `Mut` implies and the reference that `Changed` implies. However nothing guarantees that. ## Solution Documenting this assumption as a safety invariant is the least thing. --- crates/bevy_ecs/src/query/fetch.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index 3178c8a1fc128..1f7fe29ec729f 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -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(