Skip to content

Commit

Permalink
improve safety comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hymm committed Jan 29, 2024
1 parent a624068 commit 2001472
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,7 +1505,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
pub fn transmute_lens_filtered<NewD: QueryData, NewF: QueryFilter>(
&mut self,
) -> QueryLens<'_, NewD, NewF> {
// SAFETY: There are no other active borrows of data from world
// SAFETY:
// - We have exclusive access to the query
// - `self` has correctly captured it's access
// - Access is checked to be a subset of the query's access when the state is created.
let world = unsafe { self.world.world() };
let state = self.state.transmute_filtered::<NewD, NewF>(world);
QueryLens {
Expand Down Expand Up @@ -1539,7 +1542,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// See [`Self::transmute_lens`] for more details.
pub fn join<OtherD: QueryData, NewD: QueryData>(
&mut self,
other: &Query<OtherD>,
other: &mut Query<OtherD>,
) -> QueryLens<'_, NewD> {
self.join_filtered(other)
}
Expand All @@ -1558,9 +1561,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
NewF: QueryFilter,
>(
&mut self,
other: &Query<OtherD, OtherF>,
other: &mut Query<OtherD, OtherF>,
) -> QueryLens<'_, NewD, NewF> {
// SAFETY: There are no other active borrows of data from world
// SAFETY:
// - The queries have correctly captured their access.
// - We have exclusive access to both queries.
// - Access for QueryLens is checked when state is created.
let world = unsafe { self.world.world() };
let state = self
.state
Expand Down

0 comments on commit 2001472

Please sign in to comment.