From 4362b52a0124cbb91bec047b919fda13c4dbb1e0 Mon Sep 17 00:00:00 2001 From: Chris Russell <8494645+chescock@users.noreply.github.com> Date: Wed, 20 Nov 2024 22:52:10 -0500 Subject: [PATCH] Add a note to the on_unimplemented message for `QueryData` recommending `&T` and `&mut T`. (#16449) # Objective A new user is likely to try `Query` instead of `Query<&Component>`. The error message should guide them to the right solution. ## Solution Add a note to the on_unimplemented message for `QueryData` recommending `&T` and `&mut T`. The full error message now looks like: ``` error[E0277]: `A` is not valid to request as data in a `Query` --> crates\bevy_ecs\src\query\world_query.rs:260:18 | 260 | fn system(query: Query) {} | ^^^^^^^^ invalid `Query` data | = help: the trait `fetch::QueryData` is not implemented for `A` = note: if `A` is a component type, try using `&A` or `&mut A` = help: the following other types implement trait `fetch::QueryData`: &'__w mut T &Archetype &T () (F,) (F0, F1) (F0, F1, F2) (F0, F1, F2, F3) and 41 others note: required by a bound in `system::query::Query` --> crates\bevy_ecs\src\system\query.rs:362:37 | 362 | pub struct Query<'world, 'state, D: QueryData, F: QueryFilter = ()> { | ^^^^^^^^^ required by this bound in `Query` ``` --- crates/bevy_ecs/src/query/fetch.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/bevy_ecs/src/query/fetch.rs b/crates/bevy_ecs/src/query/fetch.rs index de3796190f..77f40555c2 100644 --- a/crates/bevy_ecs/src/query/fetch.rs +++ b/crates/bevy_ecs/src/query/fetch.rs @@ -272,7 +272,8 @@ use smallvec::SmallVec; /// [`ReadOnly`]: Self::ReadOnly #[diagnostic::on_unimplemented( message = "`{Self}` is not valid to request as data in a `Query`", - label = "invalid `Query` data" + label = "invalid `Query` data", + note = "if `{Self}` is a component type, try using `&{Self}` or `&mut {Self}`" )] pub unsafe trait QueryData: WorldQuery { /// The read-only variant of this [`QueryData`], which satisfies the [`ReadOnlyQueryData`] trait.