bevy/crates/bevy_reflect/src
Gino Valente 245d03a78a
bevy_reflect: Update on_unimplemented attributes (#15110)
# Objective

Some of the new compile error messages are a little unclear (at least to
me). For example:

```
error[E0277]: `tests::foo::Bar` can not be created through reflection
   --> crates/bevy_reflect/src/lib.rs:679:18
    |
679 |         #[derive(Reflect)]
    |                  ^^^^^^^ the trait `from_reflect::FromReflect` is not implemented for `tests::foo::Bar`
    |
    = note: consider annotating `tests::foo::Bar` with `#[derive(Reflect)]` or `#[derive(FromReflect)]`
```

While the annotation makes it clear that `FromReflect` is missing, it's
not very clear from the main error message.

My IDE lists errors with only their message immediately present:

<p align="center">
<img width="700" alt="Image of said IDE listing errors with only their
message immediately present. These errors are as follows:
\"`tests::foo::Bar` can not be created through reflection\", \"The trait
bound `tests::foo::Bar: RegisterForReflection` is not satisfied\", and
\"The trait bound `tests::foo::Bar: type_info::MaybeTyped` is not
satisfied\""
src="https://github.com/user-attachments/assets/42c24051-9e8e-4555-8477-51a9407446aa">
</p>

This makes it hard to tell at a glance why my code isn't compiling.

## Solution

Updated all `on_unimplemented` attributes in `bevy_reflect` to mention
the relevant trait—either the actual trait or the one users actually
need to implement—as well as a small snippet of what not implementing
them means.

For example, failing to implement `TypePath` now mentions missing a
`TypePath` implementation. And failing to implement `DynamicTypePath`
now also mentions missing a `TypePath` implementation, since that's the
actual trait users need to implement (i.e. they shouldn't implement
`DynamicTypePath` directly).

Lastly, I also added some missing `on_unimplemented` attributes for
`MaybeTyped` and `RegisterForReflection` (which you can see in the image
above).

Here's how this looks in my IDE now:

<p align="center">
<img width="700" alt="Similar image as before showing the errors listed
by the IDE. This time the errors read as follows: \"`tests::foo::Bar`
does not implement `FromReflect` so cannot be reified through
reflection\", \"`tests::foo::Bar` does not implement
`GetTypeRegistration` so cannot be registered for reflection\", and
\"`tests::foo::Bar` does not implement `Typed` so cannot provide static
type information\""
src="https://github.com/user-attachments/assets/f6f8501f-0450-4f78-b84f-00e7a18d0533">
</p>


## Testing

You can test by adding the following code and verifying the compile
errors are correct:

```rust
#[derive(Reflect)]
struct Foo(Bar);

struct Bar;
```
2024-09-09 16:26:17 +00:00
..
enums bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
func bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
impls Remove remnant EntityHash and related types from bevy_utils (#15039) 2024-09-09 15:24:17 +00:00
path bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
serde bevy_reflect: Refactor serde module (#15107) 2024-09-09 14:03:42 +00:00
array.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
attributes.rs Fix intra-doc links and make CI test them (#14076) 2024-07-11 13:08:31 +00:00
fields.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
from_reflect.rs bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
lib.rs bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
list.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
map.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
reflect.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
remote.rs bevy_reflect: Reflect remote types (#6042) 2024-08-12 19:12:53 +00:00
set.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
std_traits.rs fix nightly clippy warnings (#6395) 2022-10-28 21:03:01 +00:00
struct_trait.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
tuple_struct.rs bevy_reflect: Add Type type (#14838) 2024-08-25 17:57:07 +00:00
type_info.rs bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
type_path.rs bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
type_registry.rs bevy_reflect: Update on_unimplemented attributes (#15110) 2024-09-09 16:26:17 +00:00
utility.rs Split GenericTypeCell::get_or_insert into smaller pieces (#14865) 2024-08-26 18:20:01 +00:00