Closed

Description
when initalizing a static using a const_fn that returns a pointer to the interior of the static, rustc panics.
#![feature(const_fn)]
struct S(pub &'static u32, pub u32);
const fn g(ss: &S) -> &u32 { &ss.1 }
static s: S = S(g(&s), 0);
fn main () { }
instead of s
being initialized with a reference to its interior, the compiler panics:
error: internal compiler error: librustc_trans/mir/constant.rs:232: loading from `static` (({ i32*, i32 }*:@_ZN3foo1s17h92f76ce7d8965747E = internal global { i32*, i32 })) in constant
--> foo.rs:5:30
|
5 | const fn g(ss: &S) -> &u32 { &ss.1 }
| ^^^^^
thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:482:9
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 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:380
3: std::panicking::default_hook
at libstd/panicking.rs:396
4: std::panicking::rust_panic_with_hook
at libstd/panicking.rs:576
5: std::panicking::begin_panic
6: rustc_errors::Handler::span_bug
7: <std::thread::local::LocalKey<T>>::with
8: rustc::ty::context::tls::with_opt
9: rustc::session::span_bug_fmt
10: rustc_trans::mir::constant::MirConstContext::const_place
11: rustc_trans::mir::constant::MirConstContext::trans
12: rustc_trans::mir::constant::MirConstContext::trans_def
13: rustc_trans::mir::constant::MirConstContext::trans
14: rustc_trans::mir::constant::MirConstContext::trans_def
15: rustc_trans::consts::trans_static
16: rustc_trans::trans_item::MonoItemExt::define
17: rustc_trans::base::compile_codegen_unit
18: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::compute_result
19: rustc::dep_graph::graph::DepGraph::with_task_impl
20: rustc_errors::Handler::track_diagnostics
21: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
22: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::force
23: rustc::ty::maps::<impl rustc::ty::maps::queries::compile_codegen_unit<'tcx>>::try_get
24: rustc::ty::maps::TyCtxtAt::compile_codegen_unit
25: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::compile_codegen_unit
26: rustc_trans::base::trans_crate
27: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
28: rustc::util::common::time
29: rustc_driver::driver::phase_4_translate_to_llvm
30: rustc_driver::driver::compile_input::{{closure}}
31: <std::thread::local::LocalKey<T>>::with
32: <std::thread::local::LocalKey<T>>::with
33: rustc::ty::context::TyCtxt::create_and_enter
34: rustc_driver::driver::compile_input
35: rustc_driver::run_compiler
rustc --version --verbose
:
rustc 1.25.0-nightly (56733bc9f 2018-02-01)
binary: rustc
commit-hash: 56733bc9f8302409a2b6110f422512923c878154
commit-date: 2018-02-01
host: x86_64-unknown-linux-gnu
release: 1.25.0-nightly
LLVM version: 4.0