-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Identify which tuple item fails to implement a trait when using fake variadics #141258
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
Comments
👍 for attempting to detect and diagnose this case, when looking for a trait impl for a tuple. |
I quite like the output! Agreed on leaving more complex retry logic for later: the key thing here is showcasing which element didn't meet the trait bounds. |
This looks great. Nevertheless I would like to raise a few points to prevent future problems. @estebank Mentions that the logic could in the future retry with different combinations. While that would be really useful, it is likely also very important to be carefully with which combinations should be retried. For example diesel has this The other thing I want to mention in this context is yet another idea that might help to improve error messages around such tuple impls significantly. At least in diesel (and I assume in bevy) as well there are often trait impls like |
@weiznich very important points. Yes, we should have a limit on how many things we try. I think an example of the second case would be useful and should be handled separately. |
I've put together a minimal example for the second case here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=6cc46789f0f7bd40298c7ca91f91575a |
Detect method not being present that is present in other tuple types When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general. <img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" /> Address rust-lang#141258. I believe that more combination of cases in the tuple types should be handled (like adding borrows and checking when a specific type needs to not be a borrow while the rest stay the same), but for now this handles the most common case.
Detect method not being present that is present in other tuple types When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general. <img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" /> Address rust-lang#141258. I believe that more combination of cases in the tuple types should be handled (like adding borrows and checking when a specific type needs to not be a borrow while the rest stay the same), but for now this handles the most common case.
Rollup merge of #142034 - estebank:issue-141258, r=davidtwco Detect method not being present that is present in other tuple types When a method is not present because of a trait bound not being met, and that trait bound is on a tuple, we check if making the tuple have no borrowed types makes the method to be found and highlight it if it does. This is a common problem for Bevy in particular and ORMs in general. <img width="1166" alt="Screenshot 2025-06-04 at 10 38 24 AM" src="https://github.com/user-attachments/assets/d257c9ea-c2d7-42e7-8473-8b93aa54b8e0" /> Address #141258. I believe that more combination of cases in the tuple types should be handled (like adding borrows and checking when a specific type needs to not be a borrow while the rest stay the same), but for now this handles the most common case.
Uh oh!
There was an error while loading. Please reload this page.
Code
Current output
Desired output
Rationale and extra context
This is an extremely common pattern for Bevy, primarily in our system and bundle code patterns. The poor error messages are one of our largest UX / teaching problems,. See #89681 for that specific issue, which could be fixed by more general improvements here.
This pattern occurs all over the place: the minimal example here uses
Default
, which relies on the same flavor of fake variadics for tuples where all tuple elements implement a given trait. Bevy'sBundle
tuples matches this form exactly, while ourSystem
s use the same sort of trick but with functions, where each parameter must implementSystemParam
.Other cases
The error output when calling methods from the trait directly correctly identifies the problematic variant:
Rust Version
Anything else?
Discussed with @estebank and @joshtriplett at RustWeek 2025, where I was encouraged to file an issue so we can improve diagnostics without waiting on full variadics!
The text was updated successfully, but these errors were encountered: