Cannot access a scoped thread local variable without calling `set` first


#1

Hi! I recently got the puzzling error message reported below.

What is the meaning of “cannot access a scoped thread local variable without calling set first”? I found in a rustfmt issue that somehow it is necessary to “call syntax::with_globals before using parser”, but that function is not documented and I’m not sure when/how I’m supposed to use it.

...
thread 'main' panicked at 'cannot access a scoped thread local variable without calling `set` first', /cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-0.1.1/src/lib.rs:186: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:515
   6: std::panicking::begin_panic
   7: <scoped_tls::ScopedKey<T>>::with
   8: syntax_pos::<impl syntax_pos::span_encoding::Span>::macro_backtrace
   9: rustc_errors::emitter::EmitterWriter::fix_multispan_in_std_macros
  10: <rustc_errors::emitter::EmitterWriter as rustc_errors::emitter::Emitter>::emit
  11: rustc_errors::Handler::emit_db
  12: rustc_errors::Handler::abort_if_errors
  13: mycrate_driver::driver_utils::run::{{closure}}
             at mycrate/src/driver_utils.rs:84
  14: mycrate_driver::driver_utils::monitor::{{closure}}
             at mycrate/src/driver_utils.rs:30
  15: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /checkout/src/libstd/panic.rs:313
  16: std::panicking::try::do_call
             at /checkout/src/libstd/panicking.rs:310
  17: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  18: std::panicking::try
             at /checkout/src/libstd/panicking.rs:289
  19: std::panic::catch_unwind
             at /checkout/src/libstd/panic.rs:392
  20: rustc_driver::in_rustc_thread
             at /checkout/src/librustc_driver/lib.rs:1545
  21: mycrate_driver::driver_utils::monitor
             at mycrate/src/driver_utils.rs:29
  22: mycrate_driver::driver_utils::run
             at mycrate/src/driver_utils.rs:80
  23: mycrate_driver::main
             at mycrate/src/driver.rs:170
  24: std::rt::lang_start::{{closure}}
             at /checkout/src/libstd/rt.rs:74
  25: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  26: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:105
  27: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  28: std::rt::lang_start
             at /checkout/src/libstd/rt.rs:74
  29: main
  30: __libc_start_main
  31: _start
query stack during panic:
end of query stack

error: internal compiler error: unexpected panic
...