Closed
Description
The following code used to work, but no longer does on the latest nightly:
#![feature(extern_types, const_transmute)]
extern "C" {
pub type ExternType;
}
unsafe impl Sync for ExternType {}
#[repr(transparent)]
pub struct Wrapper(ExternType);
static MAGIC_FFI_STATIC: u8 = 42;
pub static MAGIC_FFI_REF: &'static Wrapper = unsafe {
std::mem::transmute(&MAGIC_FFI_STATIC)
};
It causes an ICE when attempting to compile it.
Backtrace:
thread 'main' panicked at 'Fields cannot be extern types', libcore/option.rs:1008:5
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::_print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: rustc::util::common::panic_hook
5: std::panicking::rust_panic_with_hook
6: std::panicking::continue_panic_fmt
7: rust_begin_unwind
8: core::panicking::panic_fmt
9: core::option::expect_failed
10: <rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::size_and_align_of
11: rustc_mir::interpret::validity::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::validate_primitive_type
12: rustc_mir::interpret::validity::<impl rustc_mir::interpret::eval_context::EvalContext<'a, 'mir, 'tcx, M>>::validate_operand
13: rustc_mir::const_eval::const_eval_provider
14: rustc::ty::query::__query_compute::const_eval
15: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
16: rustc::dep_graph::graph::DepGraph::with_task_impl
17: rustc::ty::context::tls::with_related_context
18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
20: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::const_eval
21: rustc_mir::const_eval::const_eval_provider
22: rustc::ty::query::__query_compute::const_eval
23: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::const_eval<'tcx>>::compute
24: rustc::dep_graph::graph::DepGraph::with_task_impl
25: rustc::ty::context::tls::with_related_context
26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
28: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::const_eval
29: rustc_lint::builtin::check_const
30: <rustc_lint::register_builtins::BuiltinCombinedLateLintPass as rustc::lint::LateLintPass<'a, 'tcx>>::check_item
31: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
32: <rustc::lint::context::LateContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_mod
33: rustc::hir::intravisit::walk_crate
34: rustc::lint::context::check_crate
35: rustc::util::common::time
36: rustc::ty::context::tls::enter_context
37: <std::thread::local::LocalKey<T>>::with
38: rustc::ty::context::TyCtxt::create_and_enter
39: rustc_driver::driver::compile_input
40: rustc_driver::run_compiler_with_pool
41: rustc_driver::driver::spawn_thread_pool
42: rustc_driver::run_compiler
43: <scoped_tls::ScopedKey<T>>::set
44: syntax::with_globals
45: __rust_maybe_catch_panic
46: rustc_driver::run
47: rustc_driver::main
48: std::rt::lang_start::{{closure}}
49: std::panicking::try::do_call
50: __rust_maybe_catch_panic
51: std::rt::lang_start_internal
52: main
query stack during panic:
#0 [const_eval] const-evaluating + checking `MAGIC_FFI_REF`
#1 [const_eval] const-evaluating + checking `MAGIC_FFI_REF`
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.31.0-nightly (1cf82fd9c 2018-10-30) running on x86_64-apple-darwin
note: compiler flags: --crate-type rlib
The problem appears to be the Wrapper
type. If you modify MAGIC_FFI_REF
to have the type &'static ExternType
then it compiles okay. It only fails with the type &'static Wrapper
.
My rust version: rustc 1.31.0-nightly (1cf82fd9c 2018-10-30)
.