Repository: rust
Issue: Attempted to read from stolen value error
Labels: I-ICE,T-compiler,C-bug

<!--
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 can be found at https://git.eleves.ens.fr/jcaspar/nicos/-/tree/filesystem, at commit `7d450c48843ca9978f2ea60a77bec88211381677`, however I couldn't reproduce after removing the `target` directory, so I guess this is related to incremental compilation and not to the code itself.

I have kept the `target` directory as an archive, but it's quite heavy (~100M) so I didn't upload it on the git repo. If you are interested in that archive, tell me and I'll find a way to upload it somewhere else and give you a link.

Also note that, even with the right `target` directory, I could only trigger this bug with a normal build, not with a release build.

### Meta

`rustc --version --verbose`:
```
rustc 1.68.0-nightly (d6f99e535 2023-01-02)
binary: rustc
commit-hash: d6f99e535a301a421dfee52a7c25bb4bdf420344
commit-date: 2023-01-02
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6
```

### Error output

```
thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/check_unsafety.rs:501:36
stack backtrace:
   0:     0x7f16287652ba - std::backtrace_rs::backtrace::libunwind::trace::h63336ecdb3bad04b
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f16287652ba - std::backtrace_rs::backtrace::trace_unsynchronized::he3a8c5861faa8ce5
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f16287652ba - std::sys_common::backtrace::_print_fmt::h6720fb1a10e43309
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f16287652ba - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h48bca0897c339d00
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f16287c83be - core::fmt::write::hf9f58db26479ade9
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/fmt/mod.rs:1208:17
   5:     0x7f1628755765 - std::io::Write::write_fmt::h12a31f1c80b570e7
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/io/mod.rs:1682:15
   6:     0x7f1628765085 - std::sys_common::backtrace::_print::hdbaa477a95e75642
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f1628765085 - std::sys_common::backtrace::print::h7c8b0abb49f271cd
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f1628767e4f - std::panicking::default_hook::{{closure}}::h1797033e1ed70a4e
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:267:22
   9:     0x7f1628767b8b - std::panicking::default_hook::hb3d6fe26ba7504d8
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:286:9
  10:     0x7f162ba3fd44 - <rustc_driver[8be1598210413b33]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[7ff1f80559238851]::ops::function::FnOnce<(&core[7ff1f80559238851]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7f162876868d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h4a6520846f8dc7bd
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/alloc/src/boxed.rs:2002:9
  12:     0x7f162876868d - std::panicking::rust_panic_with_hook::h6977f8300f810150
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:692:13
  13:     0x7f1628768409 - std::panicking::begin_panic_handler::{{closure}}::h2998430db00ab632
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:579:13
  14:     0x7f162876576c - std::sys_common::backtrace::__rust_end_short_backtrace::hb91fb6f55cc300a4
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys_common/backtrace.rs:137:18
  15:     0x7f1628768112 - rust_begin_unwind
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:575:5
  16:     0x7f16287c4da3 - core::panicking::panic_fmt::h4d2929ac8958f22d
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/panicking.rs:64:14
  17:     0x7f162a294164 - rustc_mir_transform[e0ceb31cae4d126]::check_unsafety::unsafety_check_result
  18:     0x7f162a293735 - <rustc_mir_transform[e0ceb31cae4d126]::check_unsafety::provide::{closure#0} as core[7ff1f80559238851]::ops::function::FnOnce<(rustc_middle[826004897f5d0702]::ty::context::TyCtxt, rustc_span[eee94698d303490b]::def_id::LocalDefId)>>::call_once
  19:     0x7f162c3cbcb4 - <rustc_middle[826004897f5d0702]::dep_graph::dep_node::DepKind as rustc_query_system[f966af2134b81d67]::dep_graph::DepKind>::with_deps::<rustc_query_system[f966af2134b81d67]::query::plumbing::try_load_from_disk_and_cache_in_memory<rustc_query_impl[949cbd89f0df975a]::queries::unsafety_check_result, rustc_query_impl[949cbd89f0df975a]::plumbing::QueryCtxt>::{closure#1}, &rustc_middle[826004897f5d0702]::mir::query::UnsafetyCheckResult>
  20:     0x7f162a714ade - rustc_query_system[f966af2134b81d67]::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl[949cbd89f0df975a]::queries::unsafety_check_result, rustc_query_impl[949cbd89f0df975a]::plumbing::QueryCtxt>
  21:     0x7f162a713b0d - rustc_query_system[f966af2134b81d67]::query::plumbing::try_execute_query::<rustc_query_impl[949cbd89f0df975a]::queries::unsafety_check_result, rustc_query_impl[949cbd89f0df975a]::plumbing::QueryCtxt>
  22:     0x7f162b409f04 - <rustc_query_impl[949cbd89f0df975a]::Queries as rustc_middle[826004897f5d0702]::ty::query::QueryEngine>::unsafety_check_result
  23:     0x7f1629f0ba82 - rustc_mir_transform[e0ceb31cae4d126]::check_unsafety::check_unsafety
  24:     0x7f1629f0adb4 - <rustc_session[f986e2fc2eb399bc]::session::Session>::time::<(), rustc_interface[1f30c620a2179fec]::passes::analysis::{closure#3}>
  25:     0x7f1629f06abe - rustc_interface[1f30c620a2179fec]::passes::analysis
  26:     0x7f162b19bee6 - <rustc_query_system[f966af2134b81d67]::dep_graph::graph::DepGraph<rustc_middle[826004897f5d0702]::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle[826004897f5d0702]::ty::context::TyCtxt, (), core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>
  27:     0x7f162b19b0a1 - rustc_query_system[f966af2134b81d67]::query::plumbing::try_execute_query::<rustc_query_impl[949cbd89f0df975a]::queries::analysis, rustc_query_impl[949cbd89f0df975a]::plumbing::QueryCtxt>
  28:     0x7f162b40631a - <rustc_query_impl[949cbd89f0df975a]::Queries as rustc_middle[826004897f5d0702]::ty::query::QueryEngine>::analysis
  29:     0x7f162accc703 - <rustc_interface[1f30c620a2179fec]::passes::QueryContext>::enter::<rustc_driver[8be1598210413b33]::run_compiler::{closure#1}::{closure#2}::{closure#2}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>
  30:     0x7f162acc77f4 - rustc_span[eee94698d303490b]::with_source_map::<core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>, rustc_interface[1f30c620a2179fec]::interface::run_compiler<core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>, rustc_driver[8be1598210413b33]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  31:     0x7f162acbfb25 - <scoped_tls[5561f9902316343e]::ScopedKey<rustc_span[eee94698d303490b]::SessionGlobals>>::set::<rustc_interface[1f30c620a2179fec]::interface::run_compiler<core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>, rustc_driver[8be1598210413b33]::run_compiler::{closure#1}>::{closure#0}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>
  32:     0x7f162acbf112 - std[5af4ca9a55fdc83a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[1f30c620a2179fec]::util::run_in_thread_pool_with_globals<rustc_interface[1f30c620a2179fec]::interface::run_compiler<core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>, rustc_driver[8be1598210413b33]::run_compiler::{closure#1}>::{closure#0}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>
  33:     0x7f162acbeeba - <<std[5af4ca9a55fdc83a]::thread::Builder>::spawn_unchecked_<rustc_interface[1f30c620a2179fec]::util::run_in_thread_pool_with_globals<rustc_interface[1f30c620a2179fec]::interface::run_compiler<core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>, rustc_driver[8be1598210413b33]::run_compiler::{closure#1}>::{closure#0}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ff1f80559238851]::result::Result<(), rustc_errors[354c2efffe60ff2a]::ErrorGuaranteed>>::{closure#1} as core[7ff1f80559238851]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  34:     0x7f1628772b43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h61f61231edf9a6d9
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/alloc/src/boxed.rs:1988:9
  35:     0x7f1628772b43 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h1c78fbbf2ddb4167
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/alloc/src/boxed.rs:1988:9
  36:     0x7f1628772b43 - std::sys::unix::thread::Thread::new::thread_start::hd8b08a93cd21b34f
                               at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/sys/unix/thread.rs:108:17
  37:     0x7f1628488e86 - start_thread
  38:     0x7f162850fce0 - clone3
  39:                0x0 - <unknown>

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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.68.0-nightly (d6f99e535 2023-01-02) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [unsafety_check_result] unsafety-checking `_::__BOOTLOADER_CONFIG::{constant#0}`
#1 [analysis] running analysis passes on this crate
end of query stack
```

<!--
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>

```thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/check_unsafety.rs:501:36
stack backtrace:
   0: rust_begin_unwind
             at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/d6f99e535a301a421dfee52a7c25bb4bdf420344/library/core/src/panicking.rs:64:14
   2: rustc_mir_transform::check_unsafety::unsafety_check_result
   3: <rustc_mir_transform::check_unsafety::provide::{closure#0} as core::ops::function::FnOnce<(rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId)>>::call_once
   4: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory<rustc_query_impl::queries::unsafety_check_result, rustc_query_impl::plumbing::QueryCtxt>::{closure#1}, &rustc_middle::mir::query::UnsafetyCheckResult>
   5: rustc_query_system::query::plumbing::try_load_from_disk_and_cache_in_memory::<rustc_query_impl::queries::unsafety_check_result, rustc_query_impl::plumbing::QueryCtxt>
   6: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::unsafety_check_result, rustc_query_impl::plumbing::QueryCtxt>
   7: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::unsafety_check_result
   8: rustc_mir_transform::check_unsafety::check_unsafety
   9: <rustc_session::session::Session>::time::<(), rustc_interface::passes::analysis::{closure#3}>
  10: rustc_interface::passes::analysis
  11: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  12: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  14: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#2}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
  15: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  16: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

```

</p>
</details>