Skip to content

error msg "Add/AddAssign (etc) is not implemented for the type _" poor for beginners #34297

Closed

Description

Reduced version of code encountered during a tutorial:

fn main() {
    let x = 0;
    x += 1.0;
}

Compiler error message:

error: the trait bound `_: std::ops::AddAssign<_>` is not satisfied [--explain E0277]
 --> <anon>:3:5
3 |>     x += 1.0;
  |>     ^^^^^^^^
help: the following implementations were found:
help:   <f64 as std::ops::AddAssign>
help:   <f32 as std::ops::AddAssign>
help:   <u64 as std::ops::AddAssign>
help:   <i64 as std::ops::AddAssign>
help: and 21 others

error: aborting due to previous error

Namely, the error message says nothing about i32 nor f64 nor the use of let x = 0;, so a beginner really has no place to go for help here.

Can we leverage the on_unimplemented functionality to provide better feedback in the case where one is mixing i32 and f64? (Or does it not have a way to put in a more specific message depending on the types involved in this case?)

There may be an issue for this elsewhere (we all know that our error messaging when type-inference goes to numeric-fallback), but the error message here was particularly bad, and I couldn't find an existing issue quickly, so I am filing this one to make sure this doesn't fall through the cracks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions