Nonsensical Suggestion from Compiler to add trait already defined

Running into a strange error here:

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:

https://github.com/rust-lang/rust/issues/61730

https://github.com/rust-lang/rust/issues/43408

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:
https://github.com/rust-lang/rfcs/pull/2000
Tracking Issue:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.