Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recent nightly doesn't support array length from indirectly referenced trait constant #67743

Closed
azriel91 opened this issue Dec 31, 2019 · 5 comments · Fixed by #68285
Closed
Assignees
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@azriel91
Copy link
Contributor

azriel91 commented Dec 31, 2019

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.

@BenLewis-Seequent
Copy link

Ouput from cargo-bisect-rustc

Regression found in the compiler

searched nightlies: from nightly-2019-12-29 to nightly-2019-12-31
regressed nightly: nightly-2019-12-31
searched commits: from da3629b to a9dd56f
regressed commit: 214548b

@jonas-schievink jonas-schievink added C-bug Category: This is a bug. I-nominated regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 31, 2019
@jonas-schievink
Copy link
Contributor

cc @oli-obk

@pnkfelix
Copy link
Member

pnkfelix commented Jan 2, 2020

triage P-high, removing nomination.

@pnkfelix
Copy link
Member

pnkfelix commented Jan 16, 2020

A user reports that this is blocking the Rust Playground from updating its nightly. (See rust-lang/rust-playground#560 )

Nominating for discussion at today's meeting.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 16, 2020

Sorry everyone, I totally forgot about this. A fix PR is up now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. P-high High priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants