Skip to content

Commit

Permalink
Deprecate Query::single_inner
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Feb 27, 2025
1 parent 0403735 commit 834f830
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_ecs/compile_fail/tests/ui/query_to_readonly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ fn for_loops(mut query: Query<&mut Foo>) {
fn single_mut_query(mut query: Query<&mut Foo>) {
// this should fail to compile
{
let mut mut_foo = query.single_mut();
let mut mut_foo = query.get_single_mut().unwrap();

// This solves "temporary value dropped while borrowed"
let readonly_query = query.as_readonly();
//~^ E0502

let ref_foo = readonly_query.single();
let ref_foo = readonly_query.get_single().unwrap();

*mut_foo = Foo;

Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ecs/src/query/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1608,7 +1608,7 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
note = "Please use `get_single` instead, which returns a `Result` instead of panicking."
)]
pub fn single<'w>(&mut self, world: &'w World) -> ROQueryItem<'w, D> {
self.query(world).single_inner()
self.query(world).get_single_inner().unwrap()
}

/// Returns a single immutable query result when there is exactly one entity matching
Expand Down Expand Up @@ -1701,7 +1701,7 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
note = "Please use `get_single_mut` instead, which returns a `Result` instead of panicking."
)]
pub fn single_mut<'w>(&mut self, world: &'w mut World) -> D::Item<'w> {
self.query_mut(world).single_inner()
self.query_mut(world).get_single_inner().unwrap()
}

/// Returns a single mutable query result when there is exactly one entity matching
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_ecs/src/system/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1852,7 +1852,7 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// # struct Health(u32);
/// #
/// fn regenerate_player_health_system(query: Query<&mut Health, With<Player>>) {
/// let mut health = query.single_inner();
/// let mut health = query.get_single_inner().unwrap();
/// health.0 += 1;
/// }
/// # bevy_ecs::system::assert_is_system(regenerate_player_health_system);
Expand All @@ -1864,6 +1864,10 @@ impl<'w, 's, D: QueryData, F: QueryFilter> Query<'w, 's, D, F> {
/// - [`single`](Self::single) to get the read-only query item.
/// - [`single_mut`](Self::single_mut) to get the mutable query item.
#[track_caller]
#[deprecated(
since = "0.16.0",
note = "Please use `get_single_inner` instead, which returns a `Result` instead of panicking."
)]
pub fn single_inner(self) -> D::Item<'w> {
self.get_single_inner().unwrap()
}
Expand Down

0 comments on commit 834f830

Please sign in to comment.