-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 diagnostics for duplicate enum discriminants #97533
Comments
Another thing we might want to do is report all the duplicates in one error, instead of generating a new error for every collision. So currently for:
We get the errors:
It would be nice if we instead got:
|
@rustbot claim |
I don't have time to work on this, unfortunately. I did get all the errors to show up in the same error message, will paste the code here when I get to my computer. @rustbot release-assignment |
Thanks for the effort. I have a bunch of spare time going forwards so I can pick up where you left off |
Perfect! My changes are in this fork Basically I've factored out the duplicate-checking code into a separate function in rustc_typeck/check/check.rs. I've also added a couple of derive macros to make sure that The code now displays all duplicates in one message. What I haven't figured out, however, is how to check that a Best of luck! |
@rustbot claim |
This is split out from the discussion in #97319.
First, the existing error for duplicate enum discriminants could be improved. The best summary of what we have now can be seen in the test added for #97319, which fixes part of it:
Which outputs:
I suggested that the last version of the error should suggest explicitly stating that the discriminant for
Last
is computed as(Second = -2) + (1 variant later) = -1 = First
, or somehow better wording that. Essentially, make it clear to the user that things are incremented positively, regardless of the order of existing discriminants.Secondly, @Bryysen suggested that the code that does this (
check_enum
) could definitely use some additional refactoring as well in this comment.The text was updated successfully, but these errors were encountered: