Repository: rust
Issue: Scoped TLS panic when making docs with --markdown-before-content
Labels: T-rustdoc,I-ICE,C-bug,E-needs-mcve

<!--
Thank you for finding an Internal Compiler Error! 🧊  If possible, try to provide
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
how to create smaller examples.
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
-->

### Code

The code is the one in my repository https://github.com/sylbeth/gdext-generation/, using the following config.toml:
```toml
[build]
rustdocflags = ["--cfg", "docsrs", "--document-private-items", "-Zunstable-options", "--generate-link-to-definition", "--markdown-before-content", "README.md"]
```
And the next command:
cargo +nightly doc --all-features --no-deps --open


### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
rustc 1.85.0-nightly (327c7ee43 2024-12-13)
binary: rustc
commit-hash: 327c7ee4367ea587a49eff1d4715f462ab6db5f0
commit-date: 2024-12-13
host: x86_64-pc-windows-msvc
release: 1.85.0-nightly
LLVM version: 19.1.5
```

### Error output

```
thread 'main' panicked at /rust/deps\scoped-tls-1.0.1\src\lib.rs:168:9:
cannot access a scoped thread local variable without calling `set` first
stack backtrace:
   0:     0x7ffadb8d9453 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffadb8d9453 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffadb8d9453 - std::backtrace::Backtrace::create
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\backtrace.rs:331
   3:     0x7ffadb8d939a - std::backtrace::Backtrace::force_capture
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\backtrace.rs:312
   4:     0x7ffadcedade1 - core[d89699aec5627831]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[476e5cdef0fa32e0]::Level, &str), usize), <((rustc_lint_defs[476e5cdef0fa32e0]::Level, &str), usize) as core[d89699aec5627831]::cmp::PartialOrd>::lt>
   5:     0x7ffadb8f44a2 - alloc::boxed::impl$30::call
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\alloc\src\boxed.rs:1984
   6:     0x7ffadb8f44a2 - std::panicking::rust_panic_with_hook
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:825
   7:     0x7ffadb8f432d - std::panicking::begin_panic::closure$0<ref$<str$> >
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:754
   8:     0x7ffadb8f19ef - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic::closure_env$0<ref$<str$> >,never$>
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\sys\backtrace.rs:168
   9:     0x7ffade79a926 - std::panicking::begin_panic<ref$<str$> >
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:753
  10:     0x7ffadce63c7b - <rustc_span[a38e50e4bd2ec1f2]::symbol::Symbol>::intern
  11:     0x7ff6ec023277 - <unknown>
  12:     0x7ff6ec020b32 - <unknown>
  13:     0x7ff6ec02c178 - <unknown>
  14:     0x7ff6ebe5d648 - <unknown>
  15:     0x7ff6ebd23882 - <unknown>
  16:     0x7ff6ec03c4ca - <unknown>
  17:     0x7ff6ebff26e0 - <unknown>
  18:     0x7ff6ebfad80f - <unknown>
  19:     0x7ff6ec13321b - <unknown>
  20:     0x7ff6ec12daf1 - <unknown>
  21:     0x7ff6ebcf1006 - <unknown>
  22:     0x7ff6ebcf101c - <unknown>
  23:     0x7ffadb8d6f7c - std::rt::lang_start_internal::closure$1
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\rt.rs:174
  24:     0x7ffadb8d6f7c - std::panicking::try::do_call
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:573
  25:     0x7ffadb8d6f7c - std::panicking::try
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:536
  26:     0x7ffadb8d6f7c - std::panic::catch_unwind
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panic.rs:358
  27:     0x7ffadb8d6f7c - std::rt::lang_start_internal
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\rt.rs:174
  28:     0x7ff6ebcf106c - <unknown>
  29:     0x7ff6ec2fb928 - <unknown>
  30:     0x7ffba812257d - BaseThreadInitThunk
  31:     0x7ffba91caf28 - RtlUserThreadStart


rustc version: 1.85.0-nightly (327c7ee43 2024-12-13)
platform: x86_64-pc-windows-msvc
```

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Backtrace</strong></summary>
<p>

```
stack backtrace:
   0:     0x7ffadb8f0f11 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffadb8f0f11 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffadb8f0f11 - std::sys::backtrace::_print_fmt
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\sys\backtrace.rs:66
   3:     0x7ffadb8f0f11 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\sys\backtrace.rs:39
   4:     0x7ffadb9231ea - core::fmt::rt::Argument::fmt
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\core\src\fmt\rt.rs:177
   5:     0x7ffadb9231ea - core::fmt::write
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\core\src\fmt\mod.rs:1437
   6:     0x7ffadb8e7217 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\io\mod.rs:1887
   7:     0x7ffadb8f0d55 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\sys\backtrace.rs:42
   8:     0x7ffadb8f3c73 - std::panicking::default_hook::closure$1
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:284
   9:     0x7ffadb8f3a52 - std::panicking::default_hook
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:311
  10:     0x7ffadceda56a - core[d89699aec5627831]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[476e5cdef0fa32e0]::Level, &str), usize), <((rustc_lint_defs[476e5cdef0fa32e0]::Level, &str), usize) as core[d89699aec5627831]::cmp::PartialOrd>::lt>
  11:     0x7ffadb8f44a2 - alloc::boxed::impl$30::call
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\alloc\src\boxed.rs:1984
  12:     0x7ffadb8f44a2 - std::panicking::rust_panic_with_hook
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:825
  13:     0x7ffadb8f432d - std::panicking::begin_panic::closure$0<ref$<str$> >
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:754
  14:     0x7ffadb8f19ef - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic::closure_env$0<ref$<str$> >,never$>
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\sys\backtrace.rs:168
  15:     0x7ffade79a926 - std::panicking::begin_panic<ref$<str$> >
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:753
  16:     0x7ffadce63c7b - <rustc_span[a38e50e4bd2ec1f2]::symbol::Symbol>::intern
  17:     0x7ff6ec023277 - <unknown>
  18:     0x7ff6ec020b32 - <unknown>
  19:     0x7ff6ec02c178 - <unknown>
  20:     0x7ff6ebe5d648 - <unknown>
  21:     0x7ff6ebd23882 - <unknown>
  22:     0x7ff6ec03c4ca - <unknown>
  23:     0x7ff6ebff26e0 - <unknown>
  24:     0x7ff6ebfad80f - <unknown>
  25:     0x7ff6ec13321b - <unknown>
  26:     0x7ff6ec12daf1 - <unknown>
  27:     0x7ff6ebcf1006 - <unknown>
  28:     0x7ff6ebcf101c - <unknown>
  29:     0x7ffadb8d6f7c - std::rt::lang_start_internal::closure$1
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\rt.rs:174
  30:     0x7ffadb8d6f7c - std::panicking::try::do_call
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:573
  31:     0x7ffadb8d6f7c - std::panicking::try
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panicking.rs:536
  32:     0x7ffadb8d6f7c - std::panic::catch_unwind
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\panic.rs:358
  33:     0x7ffadb8d6f7c - std::rt::lang_start_internal
                               at /rustc/327c7ee4367ea587a49eff1d4715f462ab6db5f0/library\std\src\rt.rs:174
  34:     0x7ff6ebcf106c - <unknown>
  35:     0x7ff6ec2fb928 - <unknown>
  36:     0x7ffba812257d - BaseThreadInitThunk
  37:     0x7ffba91caf28 - RtlUserThreadStart
```

</p>
</details>