Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the trait core::ops::Add<()> is not implemented for i32 #39579

Closed
beamspease opened this issue Feb 6, 2017 · 2 comments
Closed

the trait core::ops::Add<()> is not implemented for i32 #39579

beamspease opened this issue Feb 6, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@beamspease
Copy link

beamspease commented Feb 6, 2017

This error message was confusing to me - at first glance, it seems like it's saying that the add operator isn't implemented for the basic integer type, which makes no sense.

I'm not sure if this would look correct for all generics, but I think it would have made more sense to me if this error message were reversed - the trait 'i32::core::ops::Add' is not implemented for '<()>'.

@abonander
Copy link
Contributor

Well, it's true. i32 does not implement Add<()>

Maybe for operator traits, the compiler should add a line clarifying:

The following operation is not supported:  i32 + ()

@steveklabnik steveklabnik added the A-diagnostics Area: Messages for errors, warnings, and lints label Feb 6, 2017
bors added a commit that referenced this issue Apr 10, 2017
Explicit help message for binop type mismatch

When trying to do `1 + Some(2)`, or some other binary operation on two
types different types without an appropriate trait implementation, provide
an explicit help message:

```rust
help: `{integer} + std::option::Option<{integer}>` has no implementation
```

Re: #39579, #38564, #37626, #39942, #34698.
@Mark-Simulacrum
Copy link
Member

This is done today.

error[E0369]: binary operation `+` cannot be applied to type `()`
 --> test.rs:2:5
  |
2 |     () + 10i32;
  |     ^^^^^^^^^^
  |
  = note: an implementation of `std::ops::Add` might be missing for `()`

error[E0277]: the trait bound `i32: std::ops::Add<()>` is not satisfied
 --> test.rs:3:5
  |
3 |     10i32 + ();
  |     ^^^^^^^^^^ the trait `std::ops::Add<()>` is not implemented for `i32`
  |
  = note: no implementation for `i32 + ()`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints
Projects
None yet
Development

No branches or pull requests

4 participants