Skip to content

Binop type mismatch error could be better #38564

Closed
@brson

Description

@brson

From the new book.

let x: i8 = 5;
let y: Option<i8> = Some(5);

let sum = x + y;

If we run this code, we get an error message like this:

error[E0277]: the trait bound `i8: std::ops::Add<std::option::Option<i8>>` is not satisfied
 -->
  |
7 | let sum = x + y;
  |           ^^^^^
  |

This error could be a lot more newbie friendly. The next section of the book even has to apologize and explain:

"Intense! What this error message is trying to say is that Rust does not understand how to add an Option and an i8, since they're different types."

cc @jonathandturner @rust-lang/docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler 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