Rust: ICE with const expression in array length

Created on 30 May 2019  路  9Comments  路  Source: rust-lang/rust

#![feature(const_generics)]

struct Stack<const N: usize> {
    stack: [u64; N / 8],
}

fn main() {}

results in:

error: internal compiler error: constant in type had an ignored error
 --> src/main.rs:4:5
  |
4 |     stack: [u64; N / 8],
  |     ^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
A-const-generics A-lazy-normalization C-bug F-const_generics I-ICE T-compiler glacier requires-nightly

Most helpful comment

As the test case in https://github.com/rust-lang/rust/pull/67906 was essentially the same as the original issue here, I don't think we need another one.

All 9 comments

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0d834551eb98a0fed48f2d5c654c2b58

error: internal compiler error: constant in type had an ignored error
 --> src/main.rs:7:5
  |
7 |     stack: MaybeUninit<[u64; N / 8]>
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:197
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   8: std::panicking::begin_panic
   9: <rustc_errors::Handler as core::ops::drop::Drop>::drop
  10: core::ptr::real_drop_in_place
  11: core::ptr::real_drop_in_place
  12: <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop
  13: core::ptr::real_drop_in_place
  14: rustc_interface::interface::run_compiler_in_existing_thread_pool
  15: std::thread::local::LocalKey<T>::with
  16: scoped_tls::ScopedKey<T>::set
  17: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Also occurs with other math operations (i.e. it is not related to division only):

#![feature(const_generics)]

pub struct S<const N: usize>([u8; N*0]);

This produces:

error: internal compiler error: constant in type had an ignored error
 --> src/main.rs:3:30
  |
3 | pub struct S<const N: usize>([u8; N*0]);
  |                              ^^^^^^^^^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17

playground link

Some code that also triggers this: playground link

Just going to note that this is currently a blocker for implementing constant bit arrays (and probably, though I haven't checked, the storage for NxM matrices).

This is an instance of #43408, please use that as the canonical issue.

It seems ICE has been fixed in latest nightly, could someone confirm it?

The snippet in the OP doesn't ICE on ef92009c1 2020-01-06.

Probably fixed by #67906, which has similar test case.

As the test case in https://github.com/rust-lang/rust/pull/67906 was essentially the same as the original issue here, I don't think we need another one.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

withoutboats picture withoutboats  路  213Comments

thestinger picture thestinger  路  234Comments

withoutboats picture withoutboats  路  211Comments

nikomatsakis picture nikomatsakis  路  412Comments

Mark-Simulacrum picture Mark-Simulacrum  路  681Comments