Closed
Description
While experimenting with constant functions I managed to generate an internal compiler error.
The code
enum Foo {
Prob,
}
impl Foo {
pub const fn as_val(&self) -> u8 {
use self::Foo::*;
match *self {
Prob => 0x1,
}
}
}
fn main() {}
Here is a link to the playground.
Although this code shouldn't compile, I would expect an error along the lines of "error: if
, match
, &&
and ||
are not stable in const fn". The compiler will produce the expected error if enum Foo has more then one variant.
The internal bug with backtrace (from playground):
error: internal compiler error: librustc_mir/transform/qualify_min_const_fn.rs:366: min_const_fn encountered `Terminator {
source_info: SourceInfo {
span: src/main.rs:10:13: 10:17,
scope: scope[0]
},
kind: falseEdges -> [real: bb2, imaginary: bb1]
}`
--> src/main.rs:10:13
|
10 | Prob => 0x1,
| ^^^^
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:538:9
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
1: std::sys_common::backtrace::print
at libstd/sys_common/backtrace.rs:71
at libstd/sys_common/backtrace.rs:59
2: std::panicking::default_hook::{{closure}}
at libstd/panicking.rs:211
3: std::panicking::default_hook
at libstd/panicking.rs:227
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:480
6: std::panicking::begin_panic
7: rustc_errors::Handler::span_bug
8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
9: rustc::ty::context::tls::with_opt::{{closure}}
10: rustc::ty::context::tls::with_context_opt
11: rustc::ty::context::tls::with_opt
12: rustc::util::bug::opt_span_bug_fmt
13: rustc::util::bug::span_bug_fmt
14: rustc_mir::transform::qualify_min_const_fn::is_min_const_fn
15: <rustc_mir::transform::qualify_consts::QualifyAndPromoteConstants as rustc_mir::transform::MirPass>::run_pass
16: rustc_mir::transform::mir_validated::{{closure}}
17: rustc_mir::transform::mir_validated
18: rustc::ty::query::__query_compute::mir_validated
19: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_validated<'tcx>>::compute
20: rustc::dep_graph::graph::DepGraph::with_task_impl
21: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
25: rustc_borrowck::borrowck::borrowck
26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::borrowck<'tcx>>::compute
27: rustc::dep_graph::graph::DepGraph::with_task_impl
28: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
31: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
32: rustc_borrowck::borrowck::check_crate
33: rustc::util::common::time
34: rustc::ty::context::tls::enter_context
35: <std::thread::local::LocalKey<T>>::with
36: rustc::ty::context::TyCtxt::create_and_enter
37: rustc_driver::driver::compile_input
38: rustc_driver::run_compiler_with_pool
39: rustc_driver::driver::spawn_thread_pool
40: rustc_driver::run_compiler
41: <scoped_tls::ScopedKey<T>>::set
42: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
43: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:102
44: rustc_driver::run
45: rustc_driver::main
46: std::rt::lang_start::{{closure}}
47: std::panicking::try::do_call
at libstd/rt.rs:59
at libstd/panicking.rs:310
48: __rust_maybe_catch_panic
at libpanic_unwind/lib.rs:102
49: std::rt::lang_start_internal
at libstd/panicking.rs:289
at libstd/panic.rs:392
at libstd/rt.rs:58
50: main
51: __libc_start_main
52: <unknown>
query stack during panic:
#0 [mir_validated] processing `Foo::as_val`
#1 [borrowck] processing `Foo::as_val`
end of query stack
error: aborting due to previous error
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.31.0-nightly (4bd4e4130 2018-10-25) running on x86_64-unknown-linux-gnu
note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin
note: some of the compiler flags provided by cargo are hidden
error: Could not compile `playground`.