Nonsensical Suggestion from Compiler to add trait already defined

Running into a strange error here:

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9a27cf2419daf634221cad848c4ff1d9

The resulting compiler error is:

Compiling playground v0.0.1 (/playground)
error[E0599]: no associated item named `MAX` found for type `T` in the current scope
  --> src/lib.rs:11:40
   |
11 | impl<T: Trait> StorageValue<[usize; T::MAX]> for Foo<T> {
   |                                        ^^^ associated item not found in `T`
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `MAX`, perhaps you need to restrict type parameter `T` with it:
   |
11 | impl<T: Trait + Trait> StorageValue<[usize; T::MAX]> for Foo<T> {
   |      ^^^^^^^^^^

error[E0599]: no associated item named `MAX` found for type `T` in the current scope
  --> src/lib.rs:12:28
   |
12 |     fn get() -> [usize; T::MAX] {
   |                            ^^^ associated item not found in `T`
   |
   = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `MAX`, perhaps you need to restrict type parameter `T` with it:
   |
11 | impl<T: Trait + Trait> StorageValue<[usize; T::MAX]> for Foo<T> {
   |      ^^^^^^^^^^

As you can see, the suggestion from the compiler is to add a trait which is already there!

How do I fix this?

<3

These are the relevant bugs:

Unfortunately neither of them appear to have any workarounds listed.

1 Like

Thank you, I will look for an alternative in the meantime.

These are not intended to work until we get const generics. Currently you can try a very experimental verision of const generics in nightly by putting #![feature(const_generics)] at the top of main.rs or lib.rs

RFC:


Tracking Issue: