I'm trying to add some tests to the rustdoc syntax highlighter. Unfortunately, my tests are panicking because the function under test needs to create a ParseSess
:
thread 'html::highlight::tests::simple_function' panicked at 'cannot access a scoped thread local variable without calling `set` first', /home/euclio/repos/rust/src/libstd/macros.rs:13:23
stack backtrace:
0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
1: core::fmt::write
2: std::io::Write::write_fmt
3: std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt
4: std::sys_common::backtrace::print
5: std::panicking::default_hook::{{closure}}
6: std::panicking::default_hook
7: std::panicking::rust_panic_with_hook
8: std::panicking::begin_panic
9: scoped_tls::ScopedKey<T>::with
10: rustc_session::parse::ParseSess::with_span_handler
11: rustc_session::parse::ParseSess::with_silent_emitter
12: rustdoc::html::highlight::highlight
13: rustdoc::html::highlight::tests::simple_function
14: std::panic::catch_unwind
15: test::run_test_in_process
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
I'm not really familiar with how TLS works inside rustc. Is this a fundamental limitation of ParseSess
? Or is there a way to work around it?