-
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
Further improve error message for E0081 #100238
Conversation
Multiple duplicate assignments of the same discriminant are now reported in the samme error. We now point out the incrementation start point for discriminants that are not explicitly assigned that are also duplicates. Removed old test related to E0081 that is now covered by error-codes/E0081.rs. Also refactored parts of the `check_enum` function.
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
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.
Thanks @Bryysen!
Could you add a little PR message to explain how you are improving the message?
I left a few comments in code too.
Sorry, was too hasty when I made the PR 😄. So in the old algorithm we would do a lazy evaluation of the discriminant values, and store them in a vec as we go. Once we evaluate a new discriminant, we would compare its value to the previously computed discriminants and if it matched any of them, we error with a duplicate. The issue with this approach is that we can't know ahead of time all the duplicates for a given discriminant My solution was to just eagerly evaluate all the discriminants, and then do a similar comparison between all discriminants as we did before. When we hit a duplicate this time, we add to the error message the span + value and shuffle that discriminant out of the Complexity wise, this should be no worse than the old algorithm (unless I've misjugded something). Hope that clears some things up. I'll take a second to go through the review comments.
The biggest improvement is reducing the verbosity for multiple duplicates of the same discriminant value. Another small improvement is that we point out where (and how) an implicit duplicate is incremented from, which can hopefully help clear confusion for new users:
However, i'm unsure about the |
due to ordering, added/improved comments and removed redundant test already caught by `E0081.rs`
Would you like me to squash the commits first @cjgillot ? And thanks for taking the time to review! |
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#100163 (Refactor: remove an unnecessary string search) - rust-lang#100212 (Remove more Clean trait implementations) - rust-lang#100238 (Further improve error message for E0081) - rust-lang#100268 (Add regression test for rust-lang#79148) - rust-lang#100294 (Update Duration::as_secs doc to point to as_secs_f64/32 for including fractional part) - rust-lang#100303 (:arrow_up: rust-analyzer) Failed merges: - rust-lang#100281 (Remove more Clean trait implementations) r? `@ghost` `@rustbot` modify labels: rollup
Closes #97533