Skip to content

Can't infer generic integer constants as floating-point #15674

Closed
@ghost

Description

fn main() {
    let x: f64 = 2.0;
    println!("{}", x / 2);
}

Returns:

expected `f64` but found `<generic integer #0>` (expected f64 but found integral variable)

Easy fix is to change the 2 to a 2.0, although that seems kind of excessive in this case. It makes more sense to make integer constants generic numbers, like Haskell does, if they're going to be generic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions