Skip to content

pow inference is not great #137644

@oriongonza

Description

@oriongonza
fn do_pow(n: i32) -> f64 {
    0.95.powi(n)
}
error[E0689]: can't call method `powi` on ambiguous numeric type `{float}`
   --> mail/mail-common/src/mailbox/attachments.rs:335:18
    |
335 |             0.95.powi(n)
    |                  ^^^^
    |
help: you must specify a concrete type for this numeric value, like `f32`
    |
335 |             0.95_f32.powi(n)
    |             ~~~~~~~~

Why can't the compiler infer that if it's being expected to produce a f64 the type should be an f64?
I can't think of any other cases outside of pow where the inference fails.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-inferenceArea: Type inferenceC-discussionCategory: Discussion or questions that doesn't represent real issues.T-typesRelevant to the types 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