-
Notifications
You must be signed in to change notification settings - Fork 12.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
Integer literal overflows in match patterns result in unhelpful error message #94239
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Comments
ArcaneNibble
added
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
labels
Feb 22, 2022
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Feb 26, 2022
Fix show error message when literal overflows in match patterns Fix rust-lang#94239 This changes overflow behavior in [fn lit_to_const](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/constant.rs#L10)
Dylan-DPC
added a commit
to Dylan-DPC/rust
that referenced
this issue
Feb 27, 2022
Fix show error message when literal overflows in match patterns Fix rust-lang#94239 This changes overflow behavior in [fn lit_to_const](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/constant.rs#L10)
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Feb 27, 2022
Fix show error message when literal overflows in match patterns Fix rust-lang#94239 This changes overflow behavior in [fn lit_to_const](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/constant.rs#L10)
This has since been partially fixed: the error message is correct for unsigned ints, but not signed ints, e.g. (playground link). fn main() {
match 0i8 {
0..=150 => {}
_ => {}
}
} @rustbot claim |
github-actions bot
pushed a commit
to rust-lang/miri
that referenced
this issue
Oct 12, 2023
Fix overflow checking in range patterns When a range pattern contains an overflowing literal, if we're not careful we might not notice the overflow and use the wrapped value. This makes for confusing error messages because linting against overflowing literals is only done in a later pass. So when a range is invalid we check for overflows to provide a better error. This check didn't use to handle negative types; this PR fixes that. First commit adds tests, second cleans up without changing behavior, third does the fix. EDIT: while I was at it, I fixed a small annoyance about the span of the overflow lint on negated literals. Fixes rust-lang/rust#94239
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given the following code:
The current output is:
Ideally the output should look like:
The text was updated successfully, but these errors were encountered: