Skip to content

Type which uses const generics leads to ICE when using Derive #60724

@Matthias247

Description

@Matthias247
Contributor

This code

#![feature(const_generics)]

#[derive(Debug)]
struct X<const N: usize> {
    a: [u32; N],
}

leads to

 --> src/lib.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

error[E0107]: wrong number of const arguments: expected 1, found 0

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `[type error]`,
 right: `usize`', src/librustc/ty/sty.rs:2279:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error

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

error: internal compiler error: unexpected panic

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

It doesn't seem Debug related, since the same happens for deriving Copy.

Activity

hellow554

hellow554 commented on May 11, 2019

@hellow554
Contributor

@rustbot modify labels: I-ICE C-Bug A-const-generics

added
A-const-genericsArea: const generics (parameters and arguments)
C-bugCategory: This is a bug.
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
on May 11, 2019
added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
on May 11, 2019
HadrienG2

HadrienG2 commented on May 11, 2019

@HadrienG2

I strongly suspect this might be because the derive(Debug) macro implementation will copy-paste N everywhere, whereas the current const generics implementation requires using {N} when instantiating a const generic type.

varkor

varkor commented on May 30, 2019

@varkor
Member

This now has only the error[E0107]: wrong number of const arguments: expected 1, found 0 error, which is the same as #61346, so maybe a fix for one will also address the other.

andreytkachenko

andreytkachenko commented on Jun 5, 2019

@andreytkachenko

Can confirm, in case:

pub struct Test<const X: usize>(pub [usize; X]);

compiler complain that [T, _] not derives Debug, what is expected because it does not exists in core yet:

4 | pub struct Test<const X: usize>(pub [usize; X]);
  |                                 ^^^^^^^^^^^^^^ `[usize; _]` cannot be formatted using `{:?}` because it doesn't implement `std::fmt::Debug`
  |
  = help: the trait `std::fmt::Debug` is not implemented for `[usize; _]`
  = note: required because of the requirements on the impl of `std::fmt::Debug` for `&[usize; _]`
  = note: required for the cast to the object type `dyn std::fmt::Debug`
added 3 commits that reference this issue on Jun 10, 2019
050262a
3e4a820
e181139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @Centril@hellow554@HadrienG2@andreytkachenko@varkor

    Issue actions

      Type which uses const generics leads to ICE when using Derive · Issue #60724 · rust-lang/rust