Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_reflect: Update on_unimplemented attributes #15110

Merged

Conversation

MrGVSV
Copy link
Member

@MrGVSV MrGVSV commented Sep 9, 2024

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:

Image of said IDE listing errors with only their message immediately present. These errors are as follows: \

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:

Similar image as before showing the errors listed by the IDE. This time the errors read as follows: \

Testing

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

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

struct Bar;

@MrGVSV MrGVSV added D-Trivial Nice and easy! A great choice to get started with Bevy C-Usability A targeted quality-of-life change that makes Bevy easier to use A-Reflection Runtime information about types S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 9, 2024
@MrGVSV
Copy link
Member Author

MrGVSV commented Sep 9, 2024

I'm not entirely sure if I should add some to the reflection subtraits like Struct, TupleStruct, etc.

Since those aren't used as bounds in the derive macro (or almost at all really), I think the normal the trait bound `tests::foo::Foo: tuple_struct::TupleStruct` is not satisfied error message is good enough.

Thoughts here? Are they worth adding or is that overkill?

Copy link
Contributor

@bushrat011899 bushrat011899 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is definitely better wording than my original messaging, good choices! I hadn't considered the way some IDEs only show the initial error statement.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 9, 2024
@MrGVSV MrGVSV force-pushed the mrgvsv/reflect/on-unimplemented branch from 26c6457 to d8836fd Compare September 9, 2024 16:13
@MrGVSV MrGVSV force-pushed the mrgvsv/reflect/on-unimplemented branch from d8836fd to 31f8f2c Compare September 9, 2024 16:13
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Sep 9, 2024
Merged via the queue into bevyengine:main with commit 245d03a Sep 9, 2024
26 checks passed
@MrGVSV MrGVSV deleted the mrgvsv/reflect/on-unimplemented branch September 9, 2024 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Reflection Runtime information about types C-Usability A targeted quality-of-life change that makes Bevy easier to use D-Trivial Nice and easy! A great choice to get started with Bevy S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

5 participants