Skip to content

Commit 2001472

Browse files
committed
improve safety comments
1 parent a624068 commit 2001472

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
@@ -1505,7 +1505,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
15051505
pub fn transmute_lens_filtered<NewD: QueryData, NewF: QueryFilter>(
15061506
&mut self,
15071507
) -> QueryLens<'_, NewD, NewF> {
1508-
// SAFETY: There are no other active borrows of data from world
1508+
// SAFETY:
1509+
// - We have exclusive access to the query
1510+
// - `self` has correctly captured it's access
1511+
// - Access is checked to be a subset of the query's access when the state is created.
15091512
let world = unsafe { self.world.world() };
15101513
let state = self.state.transmute_filtered::<NewD, NewF>(world);
15111514
QueryLens {
@@ -1539,7 +1542,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
15391542
/// See [`Self::transmute_lens`] for more details.
15401543
pub fn join<OtherD: QueryData, NewD: QueryData>(
15411544
&mut self,
1542-
other: &Query<OtherD>,
1545+
other: &mut Query<OtherD>,
15431546
) -> QueryLens<'_, NewD> {
15441547
self.join_filtered(other)
15451548
}
@@ -1558,9 +1561,12 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
15581561
NewF: QueryFilter,
15591562
>(
15601563
&mut self,
1561-
other: &Query<OtherD, OtherF>,
1564+
other: &mut Query<OtherD, OtherF>,
15621565
) -> QueryLens<'_, NewD, NewF> {
1563-
// SAFETY: There are no other active borrows of data from world
1566+
// SAFETY:
1567+
// - The queries have correctly captured their access.
1568+
// - We have exclusive access to both queries.
1569+
// - Access for QueryLens is checked when state is created.
15641570
let world = unsafe { self.world.world() };
15651571
let state = self
15661572
.state

0 commit comments

Comments
 (0)