Closed
Description
struct Foo;
impl Bar for Foo {
const BAR: usize = 1;
}
trait Bar {
const BAR: usize;
}
struct Array<S> where S: Bar {
data: [u8; S::BAR],
s: S,
}
This errors out with:
error[E0599]: no associated item named `BAR` found for type `S` in the current scope
--> src/lib.rs:12:19
|
12 | data: [u8; S::BAR],
| ^^^ associated item not found in `S`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `BAR`, perhaps you need to implement it:
candidate #1: `Bar`
Even though S::BAR
clearly does exist. The same thing happens for constants within associated types (so T::Bar::BAR
), with E0220, and this confused me a whole bunch. Instead apparently the problem is that array sizes currently require a literal or some other more consty consts (is that part of #133)?
cc @estebank.
Metadata
Metadata
Assignees
Labels
Area: Associated items (types, constants & functions)Area: Constant evaluation, covers all const contexts (static, const fn, ...)Area: const generics (parameters and arguments)Area: Messages for errors, warnings, and lintsDiagnostics: Confusing error or lint that should be reworked.Diagnostics: A structured suggestion resulting in incorrect code.Relevant to the compiler team, which will review and decide on the PR/issue.