Rust: the trait `core::ops::Add<()>` is not implemented for `i32`

Created on 6 Feb 2017  路  2Comments  路  Source: rust-lang/rust

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 '<()>'.

A-diagnostics

Most helpful comment

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 + ()

All 2 comments

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 + ()

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 + ()`
Was this page helpful?
0 / 5 - 0 ratings