-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Improve some error messages for bevy_ecs generated by nightly rustc #5786
Conversation
9e6f5e7
to
c7cde57
Compare
This commit introduces a new feature flags that let's user opt into the nightly only `#[rustc_on_unimplemented]` attribute. This attribute can be used to improve error messages generated by missing trait implementations. This commit adds annotations to two locations in bevy to improve error messages submitted as part of weiznich/rust-foundation-community-grant#3 Addresses bevyengine#1519
c7cde57
to
7adcdd2
Compare
See weiznich/rust-foundation-community-grant@e69f4f7#diff-c059c07feb90f777392b96c4c59911c9b5895882682eff9b25f7f0539338b6b0 for the relevant output changes. The exact wording of the error messages is up to discussion and can be easily changed. |
@@ -252,6 +252,10 @@ impl_param_set!(); | |||
/// # schedule.add_system_to_stage("update", write_resource_system.after("first")); | |||
/// # schedule.run_once(&mut world); | |||
/// ``` | |||
#[cfg_attr( | |||
feature = "nightly-error-messages", | |||
rustc_on_unimplemented(note = "consider adding `#[derive(bevy::Resource)]` to `{Self}`") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should match this for the Component trait :)
I am extremely excited to see the upstream work start to pay off :) Is there any way to automatically detect whether the user is on a compatible nightly version? This is most useful for beginners, so it's a shame it has to be opt-in. |
The |
It seems |
I didn't check that, but I would expect that any nightly from the last few years is compatible. The attribute does not really change much as far as I know. ekuber states that there were maybe 3 changes in the last 5 years, all of them backward compatible. As for the opt-in part: See the last part of the comment. At least I as diesel maintainer would be quite interested in having something like that on stable. Maybe we can suggest something like that to the compiler team if there is demand in the ecosystem.
I do not know the code base well enough to say if that would be feasible or not. Generally speaking if the error messages is a "… trait not implemented …" error message, then it's likely possible. I might have a look at that if you can provide an example.
That's partially correct. |
#[cfg_attr( | ||
feature = "nightly-error-messages", | ||
rustc_on_unimplemented(on( | ||
not(any(_Self = "& _", _Self = "&mut _", _Self = "()", _Self = "(_, _)")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to myself: I need to check if that actually does something or if it's unnecessary. In the second case I likely need to find a solution for false positives if Self
is a tuple or something like that.
Sure! Here's a simple failing snippet: use bevy::prelude::*;
// Should be `mut commands: Commands` as `&mut Commands` doesn't implement `SystemParam`
fn broken_system(commands: &mut Commands) {}
fn main(){
App::new().add_system(broken_system).run();
}
I'd be happy to help advocate for this; this style of work was mentioned in the lang team's roadmap as an area they'd like to move forward with and something I've personally discussed in the past with both Niko and Josh Triplett. I agree that this work is valuable as a proof of concept for how this feature could improve end user UX. I'm personally a bit nervous to merge this PR using |
@weiznich to clarify, I was wondering if there was a way to detect at runtime if the rustc version was nightly or stable, so we could avoid having a feature flag at all :) |
I should probably link this zulip discussion here as well as this seems to be highly relevant and currently ongoing.
As far as I know there is currently no way to detect which rustc version is used to compile the current crate. At least not without using a |
If this is totally opt-in and the implementation scope is small (and it looks that way to me), I'm down to merge something in this vein if it helps move this compiler effort forward / prove these features are valuable. Probably worth adding some comment explaining the rationale behind this / the scope of this effort. That being said, if merging this (as opposed to just testing this branch ourselves and leaving feedback) doesn't directly benefit the effort to stabilize (ex: help answer unanswered questions), then I think we should wait for a stable api. |
I had some discussions with ekuber about how to stabilize the corresponding attribute. He tweeted about that here. The summary of that discussion is that we both agree on that it should be possible to stabilize this "soon". Maybe even without going through a language team decision by using the existing tool attribute RFC. I'm on holiday for the next weeks,after that I plan to fill a compiler MCP for this. For this PR: It's up to you if you want to provide this improved error messages as early as possible or wait for a final compiler/language team decision. For diesel I recently shipped at least some uses of the corresponding attribute behind a feature flag, as I believe that can help users. |
Given that this message is intended to help new users, I think the added complexity of requiring nightly / enabling a feature counteracts the improved UX of the better error messages. I think we should probably wait until it stabilizes. |
Closing this out: we'll redo this properly with the stable equivalent soon :) |
This commit introduces a new feature flags that let's user opt into the
nightly only
#[rustc_on_unimplemented]
attribute. This attribute canbe used to improve error messages generated by missing trait
implementations. This commit adds annotations to two locations in bevy
to improve error messages submitted as part of
weiznich/rust-foundation-community-grant#3
Addresses #1519