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

Misleading error message when using associated const in where clause for fixed size array #44774

Closed
JDemler opened this issue Sep 22, 2017 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@JDemler
Copy link
Contributor

JDemler commented Sep 22, 2017

When using an associated const in a where clause to describe a fixed size array, the error message does not state that fixed size arrays cannot be described by associated consts.

Alas, it says, that the trait bound is not satisfied and suggests adding the trait bound.

Example rust code: Playground

struct Seq([u8; 8]);

impl From<[u8; 8]> for Seq {
    fn from(data: [u8; 8]) -> Seq {
        Seq(data)
    }
}

trait Sequence {
    const LEN: usize;
}

impl Sequence for Seq {
    const LEN: usize = 8;
}

trait ByteSequence {
    fn check();
}

impl<S> ByteSequence for S
where
    S: Sequence + From<[u8; <S as Sequence>::LEN]>,
{
    fn check() {}
}

Resulting Error message:

error[E0277]: the trait bound `S: Sequence` is not satisfied
  --> src/main.rs:23:29
   |
23 |     S: Sequence + From<[u8; <S as Sequence>::LEN]>,
   |                             ^^^^^^^^^^^^^^^^^^^^ the trait `Sequence` is not implemented for `S`
   |
   = help: consider adding a `where S: Sequence` bound
   = note: required by `Sequence::LEN`
@TimNN TimNN added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Sep 24, 2017
@bergus
Copy link

bergus commented Jun 5, 2018

Sounds like a duplicate of #44168 or #43408 (and all the other stuff related to #29646...)

@dtolnay
Copy link
Member

dtolnay commented Jun 9, 2018

Closing as a duplicate of #44168.

@dtolnay dtolnay closed this as completed Jun 9, 2018
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 C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

4 participants