-
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
Show discriminant before overflow in diagnostic for duplicate values. #87166
Show discriminant before overflow in diagnostic for duplicate values. #87166
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
99210f3
to
6cd6fc3
Compare
} | ||
} | ||
} | ||
format!("{}", evaluated) |
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: I also removed the backticks around the number. They seemed unnecessary to me: the value is always a decimal number, which already stands out from normal text quite well. But I can revert this if desired.
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.
So, I'd like to actually see a test where the first discriminant overflows (like in the OP). And I think that the backticks around the value should remain (backticks generally specify a value or code).
And finally (this one is a bit more opinionated): I feel like the exact number here isn't super helpful. It might be better to say some like "overflowed from usize
"
6cd6fc3
to
4c0ff4d
Compare
Makes sense. I added another test case in I added the backticks back, and I removed the overflow value from the main error message, leaving it only in the notes. With that, it now looks like this:
Hmm, I actually like to see the value before overflow. It lets me know that neither me nor the compiler have gone mad and we're both really talking about the same number. |
Sorry for the wait here. @bors r+ rollup |
📌 Commit 4c0ff4d has been approved by |
Thanks for the review! :) |
…laumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#86747 (Improve wording of the `drop_bounds` lint) - rust-lang#87166 (Show discriminant before overflow in diagnostic for duplicate values.) - rust-lang#88077 (Generate an iOS LLVM target with a specific version) - rust-lang#88164 (PassWrapper: adapt for LLVM 14 changes) - rust-lang#88211 (cleanup: `Span::new` -> `Span::with_lo`) - rust-lang#88229 (Suggest importing the right kind of macro.) - rust-lang#88238 (Stop tracking namespace in used_imports.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR adds the value before overflow for explicit discriminant values in the error for duplicate discriminant values.
I found it rather confusing to see only the overflowed value.
It only does this for literals, since overflows in const evaluated arithmetic are already a hard error.
This is my first PR to the compiler, so please let me know if the implementation can be improved :)
Before:
After: