Skip to content

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

Closed
@nathan

Description

@nathan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions