Closed
Description
Hello! I have a compiler assertion on rustc 1.31.0-nightly (2bd5993 2018-10-02) when combining #[thread_local]
and bad code that tries to move from the thread local global. This also occurred on an earlier nightly I tried upgrading from (months old? I didn't think to save that compiler version, sorry!)
#![feature(thread_local)]
pub struct CommandWriter {}
#[thread_local] static mut TL_COMMAND_BUFFER_WRITER : Option<Box<CommandWriter>> = Option::None;
static mut G_COMMAND_BUFFER_WRITER : Option<Box<CommandWriter>> = Option::None;
impl CommandWriter {
pub fn with_this_thread<F: FnOnce(&CommandWriter)> (f: F) {
unsafe {
f(&TL_COMMAND_BUFFER_WRITER.unwrap()); // [1] Compiler panic: thread 'main' panicked at 'assertion failed: tcx.migrate_borrowck()', librustc_mir\transform\elaborate_drops.rs:52:17
//f(&G_COMMAND_BUFFER_WRITER.unwrap()); // [2] Proper compiler error: "cannot move out of static item"
//f(&TL_COMMAND_BUFFER_WRITER.as_ref().unwrap()); // Builds fine
}
}
}
Compiler output with the code as posted and RUST_BACKTRACE=1
:
warning: static item is never used: `G_COMMAND_BUFFER_WRITER`
--> src\lib.rs:6:1
|
6 | static mut G_COMMAND_BUFFER_WRITER : Option<Box<CommandWriter>> = Option::None;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
thread 'main' panicked at 'assertion failed: tcx.migrate_borrowck()', librustc_mir\transform\elaborate_drops.rs:52:17
stack backtrace:
0: <std::sync::mpsc::RecvTimeoutError as core::fmt::Debug>::fmt
1: <std::path::Iter<'a> as core::convert::AsRef<std::path::Path>>::as_ref
2: std::panicking::take_hook
3: std::panicking::take_hook
4: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate<'tcx>> as rustc::ty::ToPredicate<'tcx>>::to_predicate
5: std::panicking::rust_panic_with_hook
6: <rustc_mir::borrow_check::nll::constraints::graph::Reverse as rustc_mir::borrow_check::nll::constraints::graph::ConstraintGraphDirecton>::end_region
7: <rustc_mir::transform::elaborate_drops::ElaborateDrops as rustc_mir::transform::MirPass>::run_pass
8: <rustc_mir::transform::MirSource as core::fmt::Debug>::fmt
9: rustc_mir::transform::optimized_mir
10: <rustc::ty::query::job::QueryInfo<'tcx> as core::fmt::Debug>::fmt
11: <rustc_target::spec::RelroLevel as rustc::session::config::dep_tracking::DepTrackingHash>::hash
12: rustc::ty::context::tls::track_diagnostic
13: rustc::dep_graph::graph::DepGraph::assert_ignored
14: rustc::ty::context::tls::track_diagnostic
15: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
16: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
17: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::optimized_mir
18: <rustc_metadata::schema::LazyState as core::fmt::Debug>::fmt
19: <rustc_metadata::schema::LazyState as core::fmt::Debug>::fmt
20: rustc_metadata::decoder::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc_metadata::decoder::DecodeContext<'a, 'tcx>>::read_u64
21: rustc_metadata::index::<impl rustc_metadata::schema::LazySeq<rustc_metadata::index::Index>>::lookup
22: rustc_metadata::dynamic_lib::dl::symbol
23: <rustc_metadata::encoder::ImplVisitor<'a, 'tcx> as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
24: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
25: rustc::ty::context::TyCtxt::encode_metadata
26: rustc_codegen_llvm::base::codegen_instance
27: rustc_codegen_llvm::type_::<impl rustc_codegen_llvm::llvm::ffi::::Type>::uint_from_ty
28: <rustc_codegen_llvm::base::ValueIter<'ll> as core::iter::iterator::Iterator>::next
29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
30: rustc_driver::target_features::add_configuration
31: rustc_driver::driver::phase_4_codegen
32: rustc_driver::profile::trace::write_style
33: <humantime::duration::Error as std::error::Error>::cause
34: <rustc_driver::pretty::NoAnn<'hir> as rustc_driver::pretty::HirPrinterSupport<'hir>>::sess
35: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
36: rustc_driver::driver::compile_input
37: rustc_driver::run_compiler
38: <env_logger::Logger as log::Log>::flush
39: rustc_driver::run_compiler
40: rustc_driver::target_features::add_configuration
41: _rust_maybe_catch_panic
42: rustc_driver::profile::dump
43: rustc_driver::main
44: <unknown>
45: std::panicking::update_panic_count
46: _rust_maybe_catch_panic
47: std::rt::lang_start_internal
48: <unknown>
49: <unknown>
50: BaseThreadInitThunk
51: RtlUserThreadStart
query stack during panic:
#0 [optimized_mir] processing `CommandWriter::with_this_thread`
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 (2bd5993ca 2018-10-02) running on x86_64-pc-windows-msvc
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
Reasonable/expected errors when the line marked [1]
is commented out and line marked [2]
is uncommented:
error[E0507]: cannot move out of static item
--> src\lib.rs:12:16
|
12 | f(&G_COMMAND_BUFFER_WRITER.unwrap()); // [2] Proper compiler error: "cannot move out of static item"
| ^^^^^^^^^^^^^^^^^^^^^^^ cannot move out of static item
error: aborting due to previous error
For more information about this error, try `rustc --explain E0507`.
Meta
rustc --version --verbose
:
rustc 1.31.0-nightly (2bd5993 2018-10-02)
binary: rustc
commit-hash: 2bd5993
commit-date: 2018-10-02
host: x86_64-pc-windows-msvc
release: 1.31.0-nightly
LLVM version: 8.0