Closed
Description
Hiya, on rustc 1.42.0-nightly (a9dd56ff9 2019-12-30)
, compilation fails when defining an array whose length is from a constant from a trait from an associated type. The code compiles fine on rustc 1.42.0-nightly (0de96d37f 2019-12-19)
.
trait TraitA {
const VALUE: usize;
}
struct A;
impl TraitA for A {
const VALUE: usize = 1;
}
trait TraitB {
type MyA: TraitA;
const VALUE: usize = Self::MyA::VALUE;
}
struct B;
impl TraitB for B {
type MyA = A;
}
fn main() {
let _ = [0; A::VALUE]; // ok
let _ = [0; B::VALUE]; // fails
// error: array lengths can't depend on generic parameters
// --> src/main.rs:22:17
// |
// 22 | let _ = [0; B::VALUE];
// | ^^^^^^^^
//
}
The error message:
error: array lengths can't depend on generic parameters
--> src/main.rs:22:17
|
22 | let _ = [0; B::VALUE];
| ^^^^^^^^
It seems similar to #67739, but in this case, size_of
isn't being used. It may also be a duplicate of #43408.
It also compiles fine on playpen nightly: 2019-12-29 da3629b05
.