Repository: rust
Issue:  unreachable!("state is never set to invalid values") is reached
Labels: A-linkage,O-windows,P-high,T-compiler,regression-from-stable-to-stable,I-unsound,C-bug,S-has-mcve,C-optimization

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:
Clone https://github.com/TheBevyFlock/bevy_quickstart and run `cargo run --release` on Windows

I expected to see this happen: Literally anything else than the standard library hitting unreachable code.

Instead, this happened: We hit this line of unreachable code: https://github.com/rust-lang/rust/blob/22a5267c83a3e17f2b763279eb24bb632c45dc6b/library/std/src/sys/sync/once/futex.rs

### 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.81.0-nightly (5affbb171 2024-07-18)
binary: rustc
commit-hash: 5affbb17153bc69a9d5d8d2faa4e399a014a211e
commit-date: 2024-07-18
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7
```

 ![image](https://github.com/user-attachments/assets/4bd555f6-210f-47d9-a13f-9d5ac7e1ebb7)

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary>Backtrace</summary>
<p>

```
thread 'main' panicked at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e\library\std\src\sync\once.rs:217:20:
internal error: entered unreachable code: state is never set to invalid values
stack backtrace:
   0:     0x7ffae5f03e3d - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffae5f03e3d - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffae5f03e3d - std::sys::backtrace::_print_fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:65
   3:     0x7ffae5f03e3d - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:40
   4:     0x7ffae5f34639 - core::fmt::rt::Argument::fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\fmt\rt.rs:173
   5:     0x7ffae5f34639 - core::fmt::write
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\fmt\mod.rs:1182
   6:     0x7ffae5efa941 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\io\mod.rs:1827
   7:     0x7ffae5f06ed7 - std::panicking::default_hook::closure$1
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:269
   8:     0x7ffae5f06ac9 - std::panicking::default_hook
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:296
   9:     0x7ffae5f076e2 - std::panicking::rust_panic_with_hook
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:800
  10:     0x7ffae5f074ef - std::panicking::begin_panic_handler::closure$0
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:667
  11:     0x7ffae5f047af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\sys\backtrace.rs:168
  12:     0x7ffae5f07106 - std::panicking::begin_panic_handler
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:665
  13:     0x7ffae5f5d6b4 - core::panicking::panic_fmt
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\core\src\panicking.rs:74
  14:     0x7ff7dfc60e01 - main
  15:     0x7ff7dfc5e391 - main
  16:     0x7ff7dfc5cc95 - main
  17:     0x7ffade9fe3e2 - bevy_app::app::App::add_boxed_plugin::he4742dca059e0ec1
  18:     0x7ff7dfc42aff - main
  19:     0x7ff7dfc4104f - main
  20:     0x7ff7dfc4103e - main
  21:     0x7ffae5eeb969 - std::rt::lang_start_internal::closure$2
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\rt.rs:141
  22:     0x7ffae5eeb969 - std::panicking::try::do_call
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:557
  23:     0x7ffae5eeb969 - std::panicking::try
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panicking.rs:521
  24:     0x7ffae5eeb969 - std::panic::catch_unwind
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\panic.rs:350
  25:     0x7ffae5eeb969 - std::rt::lang_start_internal
                               at /rustc/5affbb17153bc69a9d5d8d2faa4e399a014a211e/library\std\src\rt.rs:141
  26:     0x7ff7dfc42cec - main
  27:     0x7ff7dfcd5ba0 - invoke_main
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  28:     0x7ff7dfcd5ba0 - __scrt_common_main_seh
                               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  29:     0x7ffc426a257d - BaseThreadInitThunk
  30:     0x7ffc4366af28 - RtlUserThreadStart
error: process didn't exit successfully: `target\release\bevy_quickstart.exe` (exit code: 101)
```

</p>
</details>