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 with associated constant; 'consider adding a ' which already exists #44246

Closed
penguin42 opened this issue Sep 1, 2017 · 5 comments

Comments

@penguin42
Copy link

penguin42 commented Sep 1, 2017

The following disgusting code gives the error:

error[E0277]: the trait bound `A: std::marker::Sized` is not satisfied
  --> assocconst.rs:40:25
   |
40 |     type Res = [isize; <None0B<A> as ResU>::u];
   |                         ^^^^^^^^^ `A` does not have a constant size known at compile-time
   |
   = help: the trait `std::marker::Sized` is not implemented for `A`
   = help: consider adding a `where A: std::marker::Sized` bound
   = note: required by `None0B`

error[E0277]: the trait bound `A: Res` is not satisfied
  --> assocconst.rs:40:25
   |
40 |     type Res = [isize; <None0B<A> as ResU>::u];
   |                         ^^^^^^^^^ the trait `Res` is not implemented for `A`
   |
   = help: consider adding a `where A: Res` bound
   = note: required by `None0B`

error: aborting due to 2 previous errors

looking at the error on line 40, it's complaining about the lack of Res on A,
yet that is already present at line 37

(I'm sure this code deserves some errors, but I don't think that one is right!)

use std::marker::PhantomData;

trait Res {
      const i: isize;
}

trait ResU {
      const u: usize;
}

trait Zero : Res {
      const i: isize = 0;
}

struct Add<A: Res, B: Res> (PhantomData<A>,PhantomData<B>);
struct Minus1 (PhantomData<isize>);
impl Res for Minus1 {
    const i: isize = -1;
}

impl<A:Res, B: Res> Res for Add<A,B>
{
  const i: isize =  A::Res + B::Res; 
}

struct None0B<A: Res> (PhantomData<A>);
impl<A:Res> ResU for None0B<A>
{
    const u: usize = A::Res != 0;
}

trait ResArrT {
    type Res;
}

impl<A> ResArrT for A
  where A: Res,
        None0B<A> : ResU,
{
    type Res = [isize; <None0B<A> as ResU>::u];   // !!!! Line 40
}


fn main() {
    type Z = <Zero as ResArrT> :: Res;
}

Meta

rustc 1.20.0 (f3d6973 2017-08-27)
binary: rustc
commit-hash: f3d6973
commit-date: 2017-08-27
host: x86_64-unknown-linux-gnu
release: 1.20.0
LLVM version: 4.0

@kennytm
Copy link
Member

kennytm commented Sep 1, 2017

Hi could you please format the report to make it easier to read? Thanks. You could surround ``` around each code snippet like this:

Explanation

```
some
code
here
```

More explanation

```
more
code
here
```

@penguin42
Copy link
Author

Hi Kennytm - is that better?

@kennytm
Copy link
Member

kennytm commented Sep 1, 2017

@penguin42 Much better, thanks ❤️.

@kennytm
Copy link
Member

kennytm commented Sep 1, 2017

I think this is a duplicate of #42863. The bad error message is tracked at #44168.

@shepmaster
Copy link
Member

Closing as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants