Skip to content
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

Fix overflows in the implementation of overflowing_literals lint's help #135249

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

s-cerevisiae
Copy link

@s-cerevisiae s-cerevisiae commented Jan 8, 2025

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 (Wrong type suggested for overflowing_literals when the number is big #135248). It's fixed by using checked type conversion and returning u128 when it's the only choice.
  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 (ICE: attempt to negate with overflow #131849). Fixed by checking the number size beforehand and wrapping_neg.

Edit: extracted the type conversion part into a standalone function to separate the concern of overflowing.

@rustbot
Copy link
Collaborator

rustbot commented Jan 8, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @chenyukang (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants