Closed
Description
Probably one should never write this, and I wonder if it will be disallowed in the future.
Happens on stable, beta and nightly, in all const-forms existing (includes const generics)
pub const unsafe fn fake_type<T>() -> T {
hint_unreachable()
}
#[allow(unconditional_recursion)]
pub const unsafe fn hint_unreachable() -> ! {
hint_unreachable()
}
trait Const {
const CONSTANT: i32 = unsafe { fake_type() };
}
impl <T> Const for T {}
pub fn main() -> () {
dbg!(i32::CONSTANT);
}
Backtrace:
Compiling playground v0.0.1 (/playground)
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/3c235d5600393dfe6c36eeed34042efad8d4f26e/src/libcore/slice/mod.rs:2686:10
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
1: std::sys_common::backtrace::_print
at src/libstd/sys_common/backtrace.rs:71
2: std::panicking::default_hook::{{closure}}
at src/libstd/sys_common/backtrace.rs:59
at src/libstd/panicking.rs:197
3: std::panicking::default_hook
at src/libstd/panicking.rs:211
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
at src/libstd/panicking.rs:478
6: std::panicking::continue_panic_fmt
at src/libstd/panicking.rs:381
7: rust_begin_unwind
at src/libstd/panicking.rs:308
8: core::panicking::panic_fmt
at src/libcore/panicking.rs:85
9: core::panicking::panic_bounds_check
at src/libcore/panicking.rs:61
10: rustc_mir::interpret::eval_context::InterpretCx<M>::layout_of_local
11: rustc_mir::interpret::terminator::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::eval_fn_call::{{closure}}
12: rustc_mir::interpret::terminator::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::eval_fn_call
13: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::run
14: rustc_mir::const_eval::eval_body_using_ecx
15: rustc_mir::const_eval::const_eval_raw_provider
16: rustc::ty::query::__query_compute::const_eval_raw
17: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
18: rustc::dep_graph::graph::DepGraph::with_task_impl
19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
20: rustc_mir::interpret::eval_context::InterpretCx<M>::const_eval_raw
21: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpretCx<M>>::eval_const_to_op
22: rustc_mir::transform::const_prop::ConstPropagator::eval_constant
23: rustc_mir::transform::const_prop::ConstPropagator::const_prop
24: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::Visitor>::visit_statement
25: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
26: rustc_mir::transform::run_passes::{{closure}}
27: rustc_mir::transform::run_passes
28: rustc_mir::transform::optimized_mir
29: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
30: rustc::dep_graph::graph::DepGraph::with_task_impl
31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
32: rustc_mir::monomorphize::collector::collect_items_rec
33: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
34: rustc::util::common::time
35: rustc_mir::monomorphize::collector::collect_crate_mono_items
36: rustc::util::common::time
37: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
38: rustc::ty::query::__query_compute::collect_and_partition_mono_items
39: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::collect_and_partition_mono_items>::compute
40: rustc::dep_graph::graph::DepGraph::with_task_impl
41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
42: rustc_codegen_ssa::base::codegen_crate
43: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
44: rustc::util::common::time
45: rustc_interface::passes::start_codegen
46: rustc::ty::context::tls::enter_global
47: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
48: rustc_interface::passes::create_global_ctxt::{{closure}}
49: rustc_interface::passes::BoxedGlobalCtxt::enter
50: rustc_interface::queries::Query<T>::compute
51: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
52: rustc_interface::interface::run_compiler_in_existing_thread_pool
53: std::thread::local::LocalKey<T>::with
54: scoped_tls::ScopedKey<T>::set
55: syntax::with_globals
query stack during panic:
#0 [const_eval_raw] const-evaluating `Const::CONSTANT`
--> src/main.rs:18:10
|
18 | dbg!(i32::CONSTANT);
| ^^^^^^^^^^^^^
#1 [optimized_mir] processing `main`
#2 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
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/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.35.0 (3c235d560 2019-05-20) running on x86_64-unknown-linux-gnu
note: compiler flags: -C opt-level=3 -C codegen-units=1 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `playground`.
To learn more, run the command again with --verbose.