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

Prefer new associated numeric consts in float error messages #78382

Closed
bstrie opened this issue Oct 25, 2020 · 5 comments · Fixed by #78431
Closed

Prefer new associated numeric consts in float error messages #78382

bstrie opened this issue Oct 25, 2020 · 5 comments · Fixed by #78431
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bstrie
Copy link
Contributor

bstrie commented Oct 25, 2020

This program:

fn main() {
    let _ =  3.40282357e+38_f32;
    let _ =  1.7976931348623159e+308_f64;
}

Produces this output:

error: literal out of range for `f32`
 --> src/main.rs:2:14
  |
2 |     let _ =  3.40282357e+38_f32;
  |              ^^^^^^^^^^^^^^^^^^
  |
  = note: `#[deny(overflowing_literals)]` on by default
  = note: the literal `3.40282357e+38_f32` does not fit into the type `f32` and will be converted to `std::f32::INFINITY`

error: literal out of range for `f64`
 --> src/main.rs:3:14
  |
3 |     let _ =  1.7976931348623159e+308_f64;
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: the literal `1.7976931348623159e+308_f64` does not fit into the type `f64` and will be converted to `std::f64::INFINITY`

Note the references to std::{f32, 64}::INFINITY; these symbols have been superseded by associated consts at {f32,f64}::INFINITY (#68490).

  1. Update the error message to suggest the new symbols

  2. Determine if any of the other old symbols are contained in any error messages.

@bstrie bstrie added the A-diagnostics Area: Messages for errors, warnings, and lints label Oct 25, 2020
@bstrie
Copy link
Contributor Author

bstrie commented Oct 25, 2020

See also #73194.

@camelid camelid added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Oct 25, 2020
@JohnTitor JohnTitor added D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 26, 2020
@Rustin170506
Copy link
Member

I am working on this.
@rustbot claim

@bstrie
Copy link
Contributor Author

bstrie commented Oct 27, 2020

@estebank :

I think there are other cases where we still use the old mod consts.

I've gone and grepped through compiler/ for std::i8, std::f32, etc. and found no accidental uses there. I then grepped for each of the individual symbols listed in RFC 2700 (INFINTY, MAX, etc.) and didn't notice anything out of place. I also grepped for std::{} (as seen in this issue) and found only a hint message for things like f32::consts::PI etc which only triggers when an item isn't found at all, which won't trigger for any of the new consts. Probably safe to close this once #78431 merges.

@estebank
Copy link
Contributor

You are right. I was thinking of cases like this one https://github.com/rust-lang/rust/blob/0baf61bfdb95980c69fbfcc0fc95ce82e8d81ac9/src/test/ui/suggestions/suggest-std-when-using-type.stderr but this can likely be closed with the merge of that PR. I was operating with an abundance of caution.

@bstrie
Copy link
Contributor Author

bstrie commented Oct 27, 2020

Yeah, that's the aforementioned case that only shows up in the event of an error, so (AFAICT) that path won't be taken for the new constants since they resolve successfully.

@bors bors closed this as completed in 31cfe63 Oct 30, 2020
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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-papercut Diagnostics: An error or lint that needs small tweaks. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants