Skip to content

Commit ed773db

Browse files
committed
Misc query.rs cleanup (#5591)
# Objective - `for_each` methods inconsistently used an actual generic param or `impl Trait` change it to use `impl Trait` always, change them to be consistent - some methods returned `'w 's` or `'_ '_`, change them to return `'_ 's` ## Solution - Do what i just said --- ## Changelog - `iter_unsafe` and `get_unchecked` no longer return borrows tied to `'w` ## Migration Guide transmute the returned borrow from `iter_unsafe` and `get_unchecked` if this broke you (although preferably find a way to write your code that doesnt need to do this...)
1 parent dcdda4c commit ed773db

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

crates/bevy_ecs/src/system/query.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
283283
/// For example, `Query<(&mut A, &B, &mut C), With<D>>` will become `Query<(&A, &B, &C), With<D>>`.
284284
/// This can be useful when working around the borrow checker,
285285
/// or reusing functionality between systems via functions that accept query types.
286-
pub fn to_readonly(&self) -> Query<'_, '_, Q::ReadOnly, F::ReadOnly> {
286+
pub fn to_readonly(&self) -> Query<'_, 's, Q::ReadOnly, F::ReadOnly> {
287287
let new_state = self.state.as_readonly();
288288
// SAFETY: This is memory safe because it turns the query immutable.
289289
unsafe {
@@ -372,7 +372,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
372372
#[inline]
373373
pub fn iter_combinations<const K: usize>(
374374
&self,
375-
) -> QueryCombinationIter<'_, '_, Q::ReadOnly, F::ReadOnly, K> {
375+
) -> QueryCombinationIter<'_, 's, Q::ReadOnly, F::ReadOnly, K> {
376376
// SAFETY: system runs without conflicts with other systems.
377377
// same-system queries have runtime borrow checks when they conflict
378378
unsafe {
@@ -409,7 +409,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
409409
#[inline]
410410
pub fn iter_combinations_mut<const K: usize>(
411411
&mut self,
412-
) -> QueryCombinationIter<'_, '_, Q, F, K> {
412+
) -> QueryCombinationIter<'_, 's, Q, F, K> {
413413
// SAFETY: system runs without conflicts with other systems.
414414
// same-system queries have runtime borrow checks when they conflict
415415
unsafe {
@@ -455,7 +455,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
455455
pub fn iter_many<EntityList: IntoIterator>(
456456
&self,
457457
entities: EntityList,
458-
) -> QueryManyIter<'_, '_, Q::ReadOnly, F::ReadOnly, EntityList::IntoIter>
458+
) -> QueryManyIter<'_, 's, Q::ReadOnly, F::ReadOnly, EntityList::IntoIter>
459459
where
460460
EntityList::Item: Borrow<Entity>,
461461
{
@@ -504,7 +504,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
504504
pub fn iter_many_mut<EntityList: IntoIterator>(
505505
&mut self,
506506
entities: EntityList,
507-
) -> QueryManyIter<'_, '_, Q, F, EntityList::IntoIter>
507+
) -> QueryManyIter<'_, 's, Q, F, EntityList::IntoIter>
508508
where
509509
EntityList::Item: Borrow<Entity>,
510510
{
@@ -527,7 +527,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
527527
/// This function makes it possible to violate Rust's aliasing guarantees. You must make sure
528528
/// this call does not result in multiple mutable references to the same component
529529
#[inline]
530-
pub unsafe fn iter_unsafe(&'s self) -> QueryIter<'w, 's, Q, F> {
530+
pub unsafe fn iter_unsafe(&self) -> QueryIter<'_, 's, Q, F> {
531531
// SEMI-SAFETY: system runs without conflicts with other systems.
532532
// same-system queries have runtime borrow checks when they conflict
533533
self.state
@@ -543,7 +543,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
543543
#[inline]
544544
pub unsafe fn iter_combinations_unsafe<const K: usize>(
545545
&self,
546-
) -> QueryCombinationIter<'_, '_, Q, F, K> {
546+
) -> QueryCombinationIter<'_, 's, Q, F, K> {
547547
// SEMI-SAFETY: system runs without conflicts with other systems.
548548
// same-system queries have runtime borrow checks when they conflict
549549
self.state.iter_combinations_unchecked_manual(
@@ -564,7 +564,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
564564
pub unsafe fn iter_many_unsafe<EntityList: IntoIterator>(
565565
&self,
566566
entities: EntityList,
567-
) -> QueryManyIter<'_, '_, Q, F, EntityList::IntoIter>
567+
) -> QueryManyIter<'_, 's, Q, F, EntityList::IntoIter>
568568
where
569569
EntityList::Item: Borrow<Entity>,
570570
{
@@ -635,7 +635,7 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
635635
/// # bevy_ecs::system::assert_is_system(gravity_system);
636636
/// ```
637637
#[inline]
638-
pub fn for_each_mut<'a, FN: FnMut(QueryItem<'a, Q>)>(&'a mut self, f: FN) {
638+
pub fn for_each_mut<'a>(&'a mut self, f: impl FnMut(QueryItem<'a, Q>)) {
639639
// SAFETY: system runs without conflicts with other systems. same-system queries have runtime
640640
// borrow checks when they conflict
641641
unsafe {
@@ -701,10 +701,10 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
701701
///
702702
/// [`ComputeTaskPool`]: bevy_tasks::prelude::ComputeTaskPool
703703
#[inline]
704-
pub fn par_for_each_mut<'a, FN: Fn(QueryItem<'a, Q>) + Send + Sync + Clone>(
704+
pub fn par_for_each_mut<'a>(
705705
&'a mut self,
706706
batch_size: usize,
707-
f: FN,
707+
f: impl Fn(QueryItem<'a, Q>) + Send + Sync + Clone,
708708
) {
709709
// SAFETY: system runs without conflicts with other systems. same-system queries have runtime
710710
// borrow checks when they conflict
@@ -947,9 +947,9 @@ impl<'w, 's, Q: WorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
947947
/// this call does not result in multiple mutable references to the same component
948948
#[inline]
949949
pub unsafe fn get_unchecked(
950-
&'s self,
950+
&self,
951951
entity: Entity,
952-
) -> Result<QueryItem<'w, Q>, QueryEntityError> {
952+
) -> Result<QueryItem<'_, Q>, QueryEntityError> {
953953
// SEMI-SAFETY: system runs without conflicts with other systems.
954954
// same-system queries have runtime borrow checks when they conflict
955955
self.state
@@ -1374,7 +1374,7 @@ impl<'w, 's, Q: ReadOnlyWorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
13741374
/// # bevy_ecs::system::assert_is_system(print_selected_character_name_system);
13751375
/// ```
13761376
#[inline]
1377-
pub fn get_inner(&'s self, entity: Entity) -> Result<ROQueryItem<'w, Q>, QueryEntityError> {
1377+
pub fn get_inner(&self, entity: Entity) -> Result<ROQueryItem<'w, Q>, QueryEntityError> {
13781378
// SAFETY: system runs without conflicts with other systems.
13791379
// same-system queries have runtime borrow checks when they conflict
13801380
unsafe {
@@ -1411,7 +1411,7 @@ impl<'w, 's, Q: ReadOnlyWorldQuery, F: WorldQuery> Query<'w, 's, Q, F> {
14111411
/// # bevy_ecs::system::assert_is_system(report_names_system);
14121412
/// ```
14131413
#[inline]
1414-
pub fn iter_inner(&'s self) -> QueryIter<'w, 's, Q::ReadOnly, F::ReadOnly> {
1414+
pub fn iter_inner(&self) -> QueryIter<'w, 's, Q::ReadOnly, F::ReadOnly> {
14151415
// SAFETY: system runs without conflicts with other systems.
14161416
// same-system queries have runtime borrow checks when they conflict
14171417
unsafe {

0 commit comments

Comments
 (0)