Skip to content

[trait constants] thread 'rustc' panicked at 'assertion failed: (left == right) ...' #70942

Closed
@dwrensha

Description

@dwrensha

I'm seeing an internal compiler error on the following input (found by fuzz-rustc):

trait Nat {
    const VALUE: usize;
}

struct Zero;

impl Nat for Zero {
    const VALUE: i32 = 0;
}

fn main() {
    let _: [i32; Zero::VALUE] = [];
}
$ rustc main.rs
error[E0326]: implemented const `VALUE` has an incompatible type for trait
 --> main.rs:8:18
  |
2 |     const VALUE: usize;
  |                  ----- type in trait
...
8 |     const VALUE: i32 = 0;
  |                  ^^^ expected `usize`, found `i32`

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `8`,
 right: `4`', /rustc/485c5fb6e1bf12cd11a8fac5ee94962e17cff74b/src/libstd/macros.rs:16:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.44.0-nightly (485c5fb6e 2020-04-08) running on x86_64-unknown-linux-gnu

error: aborting due to previous error

For more information about this error, try `rustc --explain E0326`.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions