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

ICE when calling member function of const generic struct with associated constant as const parameter #80561

Closed
DarkKirb opened this issue Dec 31, 2020 · 2 comments · Fixed by #82067
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@DarkKirb
Copy link

DarkKirb commented Dec 31, 2020

I have recently been toying with const generics again and they are in a signifficantly better state than when I last used them.

Code

No special flags necessary to compile

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
pub struct SimpleStruct<const N: usize>([u8; N]);

impl<const N: usize> SimpleStruct<N> {
  pub fn new() -> Self {
    loop{}
  }
}

pub trait TraitA: Sized {
  const SIZE: usize;
  fn zero() -> Self
    where [(); Self::SIZE]:
  {
    let _: SimpleStruct<{Self::SIZE}> = SimpleStruct::<{Self::SIZE}>::new();
    loop {}
  }
}

This ICE stops occurring once you move new() out of the impl block. It happens regardless of the positioning of the zero() function.

Meta

rustc --version --verbose:

rustc 1.51.0-nightly (e22670468 2020-12-30)
binary: rustc
commit-hash: e2267046859c9ceb932abc983561d53a117089f6
commit-date: 2020-12-30
host: aarch64-unknown-linux-gnu
release: 1.51.0-nightly

also occurs on rust playground and older nightlies

Error output

error: internal compiler error: Encountered error `Unimplemented` selecting `Binder(<Self as TraitA>)` during codegen
  |
  = note: delayed at compiler/rustc_trait_selection/src/traits/codegen.rs:68:32

error: internal compiler error: ty::ConstKind::Error constructed but no error reported.
  |
  = note: delayed at /rustc/e2267046859c9ceb932abc983561d53a117089f6/compiler/rustc_middle/src/ty/consts.rs:183:43

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.51.0-nightly (e22670468 2020-12-30) running on aarch64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `testing`

Backtrace

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', compiler/rustc_errors/src/lib.rs:974:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e2267046859c9ceb932abc983561d53a117089f6/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/e2267046859c9ceb932abc983561d53a117089f6/library/std/src/panicking.rs:435:5
   2: rustc_errors::HandlerInner::flush_delayed
   3: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
   4: core::ptr::drop_in_place
   5: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
   6: core::ptr::drop_in_place
   7: rustc_span::with_source_map
   8: rustc_interface::interface::create_compiler_and_run
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@DarkKirb DarkKirb added 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. labels Dec 31, 2020
@DarkKirb DarkKirb changed the title ICE when calling generic member function of const generic struct with associated constant as parameter ICE when calling member function of const generic struct with associated constant as const parameter Dec 31, 2020
@jyn514 jyn514 added A-const-generics Area: const generics (parameters and arguments) requires-nightly This issue requires a nightly compiler in some way. F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Dec 31, 2020
@jyn514
Copy link
Member

jyn514 commented Dec 31, 2020

Slightly smaller:

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]
pub struct SimpleStruct<const N: usize>([u8; N]);

impl<const N: usize> SimpleStruct<N> {
  pub fn new() -> Self {
    loop{}
  }
}

pub trait TraitA {
  const SIZE: usize;
  fn zero()
    where [(); Self::SIZE]:
  {
    let _ = SimpleStruct::<{Self::SIZE}>::new();
  }
}

fanninpm added a commit to fanninpm/glacier that referenced this issue Jan 30, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jan 30, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 13, 2021

@rustbot claim

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. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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.

4 participants