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 https://github.com/rust-lang/rust/issues/67739, but in this case, size_of
isn't being used. It may also be a duplicate of https://github.com/rust-lang/rust/issues/43408.
It also compiles fine on playpen nightly: 2019-12-29 da3629b05
.
Ouput from cargo-bisect-rustc
searched nightlies: from nightly-2019-12-29 to nightly-2019-12-31
regressed nightly: nightly-2019-12-31
searched commits: from https://github.com/rust-lang/rust/commit/da3629b05f8f1b425a738bfe9fe9aedd47c5417a to https://github.com/rust-lang/rust/commit/a9dd56ff9a08d74c53d5cc22d18f126a12749608
regressed commit: https://github.com/rust-lang/rust/commit/214548b8afd94924c17dea456c8077931009b944
cc @oli-obk
triage P-high, removing nomination.
A user reports that this is blocking the Rust Playground from updating its nightly. (See https://github.com/integer32llc/rust-playground/issues/560 )
Nominating for discussion at today's meeting.
Sorry everyone, I totally forgot about this. A fix PR is up now.
Most helpful comment
Sorry everyone, I totally forgot about this. A fix PR is up now.