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.
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
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:also occurs on rust playground and older nightlies
Error output
Backtrace