Skip to content

Error msg is obtuse when doing float_fallback += 1; (or any int literal) #23994

@mdinger

Description

@mdinger

This may be WONTFIX but I'm reporting it in case it isn't. I'm not sure what the opinion on this is exactly anyway. The idea came from here. This error may come up very easily on rust-lang.org and so is likely very noticeable. This:

fn main() {
    let mut x = 0.0;
    x += 1;
}

Gives this error:

<anon>:3:5: 3:6 error: binary assignment operation `+=` cannot be applied to types `_` and `_` [E0368]
<anon>:3     x += 1;
             ^
error: aborting due to previous error
playpen: application terminated with error code 101

There are three issues, particularly to a new user (first time exploring rust-lang.org):

  • The distinction 0 and 0.0 may seem bizarre
  • Use of the mysterious type _ will be puzzling and makes the error confusing
  • Comparing _ and _ makes it worse.

It would be ideal if 1 could be inferred to the type of x in this case. This would also avoid this confusing error on the rust main landing page.

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