rust-lang / rust-lang/rust

better explanation when evaluation of constant value failed with overflowing literal

Open
#133,983 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-diagnostics T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
fn main() {
    const _:() = assert!(0 <= 2_147_483_648);
}
Current output
error[E0080]: evaluation of constant value failed
 --> src/main.rs:4:18
  |
4 |     const _:() = assert!(0 <= 2_147_483_648);
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: 0 <= 2_147_483_648', src/main.rs:4:18
  |
  = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

For more information about this error, try `rustc --explain E0080`.
Desired output
error[E0080]: evaluation of constant value failed
 --> src/main.rs:4:18
  |
4 |     const _:() = assert!(0 <= 2_147_483_648);
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'assertion failed: 0 <= 2_147_483_648', src/main.rs:4:18
  |
  = note: the literal `2_147_483_648` does not fit into the type `i32` whose range is `-2147483648..=2147483647`
  = help: consider using the type `u32` instead

For more information about this error, try `rustc --explain E0080`.
Rationale and extra context

See: https://users.rust-lang.org/t/const-assertion-fails-to-infer-correct-type/122166/3

Desired output based on the message returned in normal (not const) context.

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Rust reproducer and compare its const-evaluation diagnostic with the normal-context message linked in the issue. Trace the compiler diagnostic path responsible for E0080 and verify that the completed output explains the overflowing literal, its inferred type and range, and the suggested alternative type.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.