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

Display {integer}::MIN/MAX in integer range suggestions rather than the expanded value #56393

Closed
varkor opened this issue Nov 30, 2018 · 0 comments · Fixed by #62457
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@varkor
Copy link
Member

varkor commented Nov 30, 2018

fn main() {
    match 0i32 {
      1 => {} //~ ERROR
    }
}

Once exhaustive integer matching has been stabilised, we'll be getting errors like this:

error[E0004]: non-exhaustive patterns: `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered
 --> src/main.rs:5:11
  |
5 |     match 0i32 {
  |           ^^^^ patterns `-2147483648i32..=0i32` and `2i32..=2147483647i32` not covered

It would be nicer to display these as ::std::i32::MIN (or ::core, etc.) instead (or provide a hint telling the user this).

See https://github.com/rust-lang/rust/pull/56362/files/4fc5758a67e38b21e975fc9efe071dd58f4b98c6#diff-1d41dba9e92e851833cbeb40c504a40b for instance, where we display -2147483648i32 rather than ::std::i32::MIN.

@varkor varkor added the A-diagnostics Area: Messages for errors, warnings, and lints label Nov 30, 2018
zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 23, 2018
While many programmers may intuitively appreciate the significance of
magic numbers like −2147483648, Rust is about empowering everyone to
build reliable and efficient software! It's a bit more legible to
print the constant names.

The `max_as_i128`, &c. methods strewn in libsyntax are a bit
unsightly, but I fear this is really the most natural way to solve the
problem.

Resolves rust-lang#56393.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Dec 23, 2018
While many programmers may intuitively appreciate the significance of
magic numbers like −2147483648, Rust is about empowering everyone to
build reliable and efficient software! It's a bit more legible to
print the constant names.

The `max_as_i128`, &c. methods strewn in libsyntax are a bit
unsightly, but I fear this is really the most natural way to solve the
problem.

Resolves rust-lang#56393.
zackmdavis added a commit to zackmdavis/rust that referenced this issue Aug 7, 2019
While many programmers may intuitively appreciate the significance of
"magic numbers" like −2147483648, Rust is about empowering everyone to
build reliable and efficient software! It's a bit more legible to
print the constant names (even noisy fully-qualified-paths thereof).

The bit-manipulation methods mirror those in
`librustc_mir::hair::pattern::_match::all_constructors`; thanks to the
immortal Varkor for guidance.

Resolves rust-lang#56393.
bors added a commit that referenced this issue Aug 7, 2019
…_cognition, r=varkor

pretty-pretty extremal constants!

(A resurrection of the defunct #57073.)

While many programmers may intuitively appreciate the significance of "magic numbers" like −2147483648, Rust is about empowering everyone to build reliable and efficient software! It's a bit more legible to print the constant names (even noisy fully-qualified-paths thereof).

The bit-manipulation methods mirror those in `librustc_mir::hair::pattern::_match::all_constructors`; thanks to the immortal Varkor for guidance.

Resolves #56393.

r? @varkor
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant