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

Wrong Error Message "Add is not a Trait" #35987

Closed
CryZe opened this issue Aug 25, 2016 · 2 comments
Closed

Wrong Error Message "Add is not a Trait" #35987

CryZe opened this issue Aug 25, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@CryZe
Copy link
Contributor

CryZe commented Aug 25, 2016

I made a mistake while implementing Add for a type. Instead of using + for specifying multiple constraints, I accidentally used , and for some reason the compiler can't handle this very well. Instead of complaining about the , it says that Add is not a Trait

Playground Link

struct Okok<T: Clone>(T);

use std::ops::Add;

impl<T: Clone, Add> Add for Okok<T> {
    type Output = usize;

    fn add(self, rhs: Self) -> Self::Output {
        unimplemented!();
    }
}
...
error[E0404]: `Add` is not a trait
 --> <anon>:5:21
  |
5 | impl<T: Clone, Add> Add for Okok<T> {
  |                     ^^^ not a trait

error: cannot continue compilation due to previous error

This happens on both Nightly, Beta and Stable.

@petrochenkov
Copy link
Contributor

Compiler can't complain about ,, everything is syntactically correct - the first Add is interpreted as a fresh type parameter.

The error message should say something like "error: expected trait, found type parameter Add" + "note: ^^^ type parameter Add is defined here"

@CryZe
Copy link
Contributor Author

CryZe commented Aug 25, 2016

Oh yeah, that would make sense.

@brson brson added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 26, 2016
eddyb added a commit to eddyb/rust that referenced this issue Nov 9, 2016
…=sanxiyn

Point to type argument span when used as trait

Given the following code:

``` rust
struct Foo<T: Clone>(T);

use std::ops::Add;

impl<T: Clone, Add> Add for Foo<T> {
  type Output = usize;

  fn add(self, rhs: Self) -> Self::Output {
    unimplemented!();
  }
}
```

present the following output:

``` nocode
error[E0404]: `Add` is not a trait
 --> file3.rs:5:21
  |
5 | impl<T: Clone, Add> Add for Okok<T> {
  |                ---  ^^^ expected trait, found type parameter
  |                |
  |                type parameter defined here
```

Fixes rust-lang#35987.
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 T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants