Closed
Description
I tried to narrow it down as much as I could:
#[test]
fn some_test() {
use core::ops::Index;
trait MyTrait {
type ArrayType: Index<usize, Output = u8>;
const SIZE: usize;
const ARRAY: Self::ArrayType;
}
struct MyStruct;
// NOTE: When replacing `Self::SIZE` with `4` directly, no problem occurs.
impl MyTrait for MyStruct {
type ArrayType = [u8; Self::SIZE];
const SIZE: usize = 4;
const ARRAY: [u8; Self::SIZE] = [1, 2, 3, 4];
}
let res = <MyStruct as MyTrait>::ARRAY[2]; // PANICS HERE
assert_eq!(res, 3);
}
When executing RUST_BACKTRACE=1 cargo test some_test
:
error: internal compiler error: /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/compiler/rustc_codegen_ssa/src/mir/constant.rs:42:20: encountered bad ConstKind after monomorphizing: Error(DelaySpanBugEmitted(()))
--> reed-solomon-novelpoly/src/field/traits.rs:28:15
|
28 | let res = <MyStruct as MyTrait>::ARRAY[2]; // PANICS HERE
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/0035d9dcecee49d1f7349932bfa52c05a6f83641/compiler/rustc_errors/src/lib.rs:1061:9
stack backtrace:
0: std::panicking::begin_panic
1: std::panic::panic_any
2: rustc_errors::HandlerInner::span_bug
3: rustc_errors::Handler::span_bug
4: rustc_middle::ty::context::tls::with_opt
5: rustc_middle::util::bug::opt_span_bug_fmt
6: rustc_middle::util::bug::span_bug_fmt
7: rustc_codegen_ssa::mir::constant::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::eval_mir_constant
8: rustc_codegen_ssa::mir::codegen_mir
9: rustc_codegen_ssa::base::codegen_instance
10: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
11: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
12: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
13: rustc_codegen_llvm::base::compile_codegen_unit
14: rustc_codegen_ssa::base::codegen_crate
15: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
16: rustc_interface::queries::Queries::ongoing_codegen
17: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
18: rustc_span::with_source_map
19: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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.56.0-nightly (0035d9dce 2021-08-16) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
end of query stack
warning: `reed-solomon-novelpoly` (lib test) generated 48 warnings
error: could not compile `reed-solomon-novelpoly`; 48 warnings emitted
NOTE: Weirdly enough, this does not happen when running (see #88365 (comment))cargo build
or even cargo run
.
Metadata
Metadata
Assignees
Labels
Area: const generics (parameters and arguments)Category: This is a bug.`#![feature(generic_const_exprs)]`Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️Relevant to the compiler team, which will review and decide on the PR/issue.This issue requires a nightly compiler in some way.