-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Wrong type suggested for overflowing_literals
when the number is big
#135248
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
s-cerevisiae
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
Jan 8, 2025
jhpratt
added a commit
to jhpratt/rust
that referenced
this issue
Jan 16, 2025
…als-help, r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes rust-lang#135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes rust-lang#131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 16, 2025
…als-help, r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes rust-lang#135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes rust-lang#131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 16, 2025
…als-help, r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes rust-lang#135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes rust-lang#131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this issue
Jan 16, 2025
…als-help, r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes rust-lang#135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes rust-lang#131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
rust-timer
added a commit
to rust-lang-ci/rust
that referenced
this issue
Jan 16, 2025
Rollup merge of rust-lang#135249 - s-cerevisiae:fix-overflowing-literals-help, r=chenyukang Fix overflows in the implementation of `overflowing_literals` lint's help This PR fixes two overflow problems that cause the `overflowing_literals` lint to behave incorrectly in some edge cases. 1. When an integer literal is between `i128::MAX` and `u128::MAX`, an overflowing `as` cast can cause the suggested type to be overly small. It's fixed by using checked type conversion and returning `u128` when it's the only choice. (Fixes rust-lang#135248) 2. When an integer literal is `i128::MIN` but is of a smaller type, an overflowing negation cause the compiler to panic in debug build. Fixed by checking the number size beforehand and `wrapping_neg`. (Fixes rust-lang#131849) Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.
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.
Code
Current output
Desired output
Rationale and extra context
The help currently suggest to use a overly small type
i8
instead of the only fitting typeu128
.Other cases
Rust Version
Anything else?
No response
The text was updated successfully, but these errors were encountered: