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

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

Closed
Matthias247 opened this issue May 11, 2019 · 4 comments · Fixed by #61570
Closed

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

Matthias247 opened this issue May 11, 2019 · 4 comments · Fixed by #61570
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Matthias247
Copy link
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.

@hellow554
Copy link
Contributor

hellow554 commented May 11, 2019

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

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels May 11, 2019
@Centril Centril added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 11, 2019
@HadrienG2
Copy link

HadrienG2 commented May 11, 2019

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
Copy link
Member

varkor commented May 30, 2019

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
Copy link

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`

Centril added a commit to Centril/rust that referenced this issue Jun 10, 2019
Centril added a commit to Centril/rust that referenced this issue Jun 10, 2019
Centril added a commit to Centril/rust that referenced this issue Jun 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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.

7 participants