Skip to content

Confusing error message when using arithmetic operators on different number types #27604

Closed
@wesleywiser

Description

@wesleywiser
fn main() {
    let x : f32 = 1.0;
    let y = x / 10; //error: the trait `core::ops::Div<_>` is not implemented for the type `f32`
}

The error message is confusing because it reads as though you cannot divide f32s at all when the real issue is that you can't divide a f32 by any other numeric type. The error message should at least say something about the different numeric types involved. Ideally it would suggest changing 10 to 10.0 or casting the term.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions