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

weird error message for trait associated constant in array length #80462

Closed
Monadic-Cat opened this issue Dec 29, 2020 · 1 comment
Closed

weird error message for trait associated constant in array length #80462

Monadic-Cat opened this issue Dec 29, 2020 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@Monadic-Cat
Copy link
Contributor

I tried this code:

trait Unsigned {
    const REIFY: usize;
}

struct A<T: Unsigned> {
    buf: [u8; <T as Unsigned>::REIFY]
}

I expected to see an error about associated constants not being allowed in array lengths or something.

Instead, this is the error given by rustc.

error[E0277]: the trait bound `T: Unsigned` is not satisfied
 --> src/lib.rs:6:15
  |
2 |     const REIFY: usize;
  |     ------------------- required by `Unsigned::REIFY`
...
6 |     buf: [u8; <T as Unsigned>::REIFY]
  |               ^^^^^^^^^^^^^^^^^^^^^^ the trait `Unsigned` is not implemented for `T`
  |
help: consider further restricting this bound
  |
5 | struct A<T: Unsigned + Unsigned> {

(There is an additional "T is never used" error, but that one makes sense, since there are no valid uses of T in the struct definition.)

Meta

rustc --version --verbose:

rustc 1.48.0 (7eac88abb 2020-11-16)
binary: rustc
commit-hash: 7eac88abb2e57e752f3302f02be5f3ce3d7adfb4
commit-date: 2020-11-16
host: x86_64-unknown-linux-gnu
release: 1.48.0
LLVM version: 11.0

I tested this in Stable, Beta, and Nightly, on the Rust Playground.

@Monadic-Cat Monadic-Cat added the C-bug Category: This is a bug. label Dec 29, 2020
@jonas-schievink
Copy link
Contributor

Duplicate of #43408

@jonas-schievink jonas-schievink marked this as a duplicate of #43408 Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants