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

Incorrect suggestion for method call on ambiguous floating-point literal #90974

Closed
nathan opened this issue Nov 17, 2021 · 0 comments · Fixed by #90989
Closed

Incorrect suggestion for method call on ambiguous floating-point literal #90974

nathan opened this issue Nov 17, 2021 · 0 comments · Fixed by #90989
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

@nathan
Copy link
Contributor

nathan commented Nov 17, 2021

Given the following code:

println!("{}", (3.).recip());

The current output is:

error[E0689]: can't call method `recip` on ambiguous numeric type `{float}`
 --> src/main.rs:2:25
  |
2 |     println!("{}", (3.).recip());
  |                         ^^^^^
  |
help: you must specify a concrete type for this numeric value, like `f32`
  |
2 |     println!("{}", (3._f32).recip());
  |                     ~~~~~~

For more information about this error, try `rustc --explain E0689`.

However, this won't compile, since rustc doesn't accept 3._f32 as a floating-point literal. The help should add the implied 0 for us:

2 |     println!("{}", (3.0_f32).recip());
  |                     ~~~~~~~

See also #51874, a similar issue which was fixed.

@nathan nathan 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 Nov 17, 2021
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 18, 2021
…loat-ending-in-dot, r=sanxiyn

Avoid suggesting literal formatting that turns into member access

Fixes rust-lang#90974
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 18, 2021
…loat-ending-in-dot, r=sanxiyn

Avoid suggesting literal formatting that turns into member access

Fixes rust-lang#90974
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 18, 2021
…loat-ending-in-dot, r=sanxiyn

Avoid suggesting literal formatting that turns into member access

Fixes rust-lang#90974
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 18, 2021
…loat-ending-in-dot, r=sanxiyn

Avoid suggesting literal formatting that turns into member access

Fixes rust-lang#90974
@bors bors closed this as completed in a7261c3 Nov 18, 2021
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

Successfully merging a pull request may close this issue.

1 participant