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

mistyped_literal_suffix: improve integer suggestions, avoid wrong float suggestions #8742

Merged
merged 2 commits into from
Apr 24, 2022

Conversation

goth-turtle
Copy link
Contributor

This PR fixes 2 things:

  • The known problem that integer types are always suggested as signed, by suggesting an unsigned suffix for literals that wouldnt fit in the signed type, and ignores any literals too big for the corresponding unsigned type too.
  • The lint would only look at the integer part of any floating point literals without an exponent, this causing mistyped_literal_suffixes false positive and bad suggestion #6129. This just ignores those literals.

Examples:

let _ = 2_32; // still 2_i32
let _ = 234_8; // would now suggest 234_u8

// these are now ignored
let _ = 500_8;
let _ = 123_32.123;

changelog: suggest correct integer types in [mistyped_literal_suffix], ignore float literals without an exponent
fixes #6129

Instead of just always suggesting signed suffixes regardless of size
of the value, it now suggests an unsigned suffix when the value wouldn't
fit into the corresponding signed type, and ignores the literal entirely
if it is too big for the unsigned type as well.
Previously this lint would only look at the integer part of floating
point literals without an exponent, giving wrong suggestions like:

```
  |
8 |     let _ = 123_32.123;
  |             ^^^^^^^^^^ help: did you mean to write: `123.123_f32`
  |
```

Instead, it now ignores these literals.
Fixes rust-lang#6129
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @llogiq (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 24, 2022
@llogiq
Copy link
Contributor

llogiq commented Apr 24, 2022

Thank you!

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 24, 2022

📌 Commit b4a50e9 has been approved by llogiq

@bors
Copy link
Collaborator

bors commented Apr 24, 2022

⌛ Testing commit b4a50e9 with merge 388e6b7...

@bors
Copy link
Collaborator

bors commented Apr 24, 2022

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing 388e6b7 to master...

@bors bors merged commit 388e6b7 into rust-lang:master Apr 24, 2022
@goth-turtle goth-turtle deleted the mistyped-literal-suffix branch April 24, 2022 21:32
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mistyped_literal_suffixes false positive and bad suggestion
4 participants