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

Wrong type suggested for overflowing_literals when the number is big #135248

Open
s-cerevisiae opened this issue Jan 8, 2025 · 0 comments
Open
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
Copy link

Code

fn main() {
    _ = 340282366920938463463374607431768211455;
}

Current output

error: literal out of range for `i32`
 --> src/main.rs:2:9
  |
2 |     _ = 340282366920938463463374607431768211455;
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the literal `340282366920938463463374607431768211455` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
  = help: consider using the type `i8` instead
  = note: `#[deny(overflowing_literals)]` on by default

Desired output

error: literal out of range for `i32`
 --> src/main.rs:2:9
  |
2 |     _ = 340282366920938463463374607431768211455;
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the literal `340282366920938463463374607431768211455` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
  = help: consider using the type `u128` instead
  = note: `#[deny(overflowing_literals)]` on by default

Rationale and extra context

The help currently suggest to use a overly small type i8 instead of the only fitting type u128.

Other cases

Rust Version

rustc 1.83.0 (90b35a623 2024-11-26)
binary: rustc
commit-hash: 90b35a6239c3d8bdabc530a6a0816f7ff89a0aaf
commit-date: 2024-11-26
host: x86_64-unknown-linux-gnu
release: 1.83.0
LLVM version: 19.1.1

Anything else?

No response

@s-cerevisiae 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
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.
Projects
None yet
Development

No branches or pull requests

1 participant