Skip to content

Commit d29316b

Browse files
committed
improve safety comments
1 parent abdb32b commit d29316b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

crates/bevy_ecs/src/system/query.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,7 +1558,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
15581558
pub fn transmute_lens_filtered<NewD: QueryData, NewF: QueryFilter>(
15591559
&mut self,
15601560
) -> QueryLens<'_, NewD, NewF> {
1561-
// SAFETY: There are no other active borrows of data from world
1561+
// SAFETY:
1562+
// - We have exclusive access to the query
1563+
// - `self` has correctly captured it's access
1564+
// - Access is checked to be a subset of the query's access when the state is created.
15621565
let world = unsafe { self.world.world() };
15631566
let state = self.state.transmute_filtered::<NewD, NewF>(world);
15641567
QueryLens {
@@ -1592,7 +1595,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
15921595
/// See [`Self::transmute_lens`] for more details.
15931596
pub fn join<OtherD: QueryData, NewD: QueryData>(
15941597
&mut self,
1595-
other: &Query<OtherD>,
1598+
other: &mut Query<OtherD>,
15961599
) -> QueryLens<'_, NewD> {
15971600
self.join_filtered(other)
15981601
}
@@ -1611,9 +1614,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
16111614
NewF: QueryFilter,
16121615
>(
16131616
&mut self,
1614-
other: &Query<OtherD, OtherF>,
1617+
other: &mut Query<OtherD, OtherF>,
16151618
) -> QueryLens<'_, NewD, NewF> {
1616-
// SAFETY: There are no other active borrows of data from world
1619+
// SAFETY:
1620+
// - The queries have correctly captured their access.
1621+
// - We have exclusive access to both queries.
1622+
// - Access for QueryLens is checked when state is created.
16171623
let world = unsafe { self.world.world() };
16181624
let state = self
16191625
.state

0 commit comments

Comments
 (0)