Repository: rust
Issue: ICE: attempted to read from stolen value: rustc_middle::mir::Body
Labels: I-ICE,T-compiler,C-bug,S-needs-repro

<!--
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

```
fn priority(left: &[u8], right: &[u8]) -> u32 {
    let mut foo = 0;
    let mut common = b'0';
    for i in left {
        if right.contains(i) {
            common = *i;
            break;
        }
    }
    

    println!("There: {}", common);
    return match common {
        b'a'..=b'z' => (common - 96) as u32,
        b'A'..=b'Z' => (common - 64) as u32,
        _ => { println!("{}", common);
            panic!("Invalid byte")},
    };
}

fn main() {
    let total: u32 = include_bytes!("input.txt")
        .split(|x| *x == b'\n')
        .map(|x| x.split_at(x.len() / 2))
        .map(|(l, r)| priority(l, r))
        .sum::<u32>();

    println!("{total}");
}
```


### 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.69.0 (84c898d65 2023-04-16)
binary: rustc
commit-hash: 84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc
commit-date: 2023-04-16
host: x86_64-unknown-linux-gnu
release: 1.69.0
LLVM version: 15.0.7
```

### Error output

```
thread 'rustc' panicked at 'attempted to read from stolen value: rustc_middle::mir::Body', compiler/rustc_mir_transform/src/ffi_unwind_calls.rs:50:78
stack backtrace:
   0:     0x7ff64596731a - std::backtrace_rs::backtrace::libunwind::trace::ha9053a9a07ca49cb
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7ff64596731a - std::backtrace_rs::backtrace::trace_unsynchronized::h9c2852a457ad564e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7ff64596731a - std::sys_common::backtrace::_print_fmt::h457936fbfaa0070f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7ff64596731a - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h5779d7bf7f70cb0c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7ff6459cab6e - core::fmt::write::h5a4baaff1bcd3eb5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/fmt/mod.rs:1232:17
   5:     0x7ff64595a2c5 - std::io::Write::write_fmt::h4bc1f301cb9e9cce
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/io/mod.rs:1684:15
   6:     0x7ff6459670e5 - std::sys_common::backtrace::_print::h5fcdc36060f177e8
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7ff6459670e5 - std::sys_common::backtrace::print::h54ca9458b876c8bf
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7ff645969e5f - std::panicking::default_hook::{{closure}}::hbe471161c7664ed6
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:271:22
   9:     0x7ff645969b9b - std::panicking::default_hook::ha3500da57aa4ac4f
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:290:9
  10:     0x7ff648bcb8b5 - <rustc_driver_impl[fb92b3e21ac03dce]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[911a585bea10363d]::ops::function::FnOnce<(&core[911a585bea10363d]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  11:     0x7ff64596a69d - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6507bddc3eebb4a5
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:2001:9
  12:     0x7ff64596a69d - std::panicking::rust_panic_with_hook::h50c09d000dc561d2
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:696:13
  13:     0x7ff64596a419 - std::panicking::begin_panic_handler::{{closure}}::h9e2b2176e00e0d9c
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:583:13
  14:     0x7ff645967786 - std::sys_common::backtrace::__rust_end_short_backtrace::h5739b8e512c09d02
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys_common/backtrace.rs:150:18
  15:     0x7ff64596a122 - rust_begin_unwind
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
  16:     0x7ff6459c6ec3 - core::panicking::panic_fmt::hf33a1475b4dc5c3e
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
  17:     0x7ff64790f2cc - rustc_mir_transform[78e1eecd28eacd11]::ffi_unwind_calls::has_ffi_unwind_calls
  18:     0x7ff6495165ba - <rustc_middle[1a4ce3311a146f18]::dep_graph::dep_node::DepKind as rustc_query_system[caf472e4bac2b2b6]::dep_graph::DepKind>::with_deps::<rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_load_from_disk_and_cache_in_memory<rustc_query_impl[a4bd04fc7a0236b8]::queries::has_ffi_unwind_calls, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>::{closure#1}, bool>
  19:     0x7ff64790dd2b - rustc_query_system[caf472e4bac2b2b6]::query::plumbing::try_execute_query::<rustc_query_impl[a4bd04fc7a0236b8]::queries::has_ffi_unwind_calls, rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>
  20:     0x7ff64790c58a - <rustc_query_impl[a4bd04fc7a0236b8]::Queries as rustc_middle[1a4ce3311a146f18]::ty::query::QueryEngine>::has_ffi_unwind_calls
  21:     0x7ff6479bf844 - <rustc_query_impl[a4bd04fc7a0236b8]::queries::has_ffi_unwind_calls as rustc_query_system[caf472e4bac2b2b6]::query::config::QueryConfig<rustc_query_impl[a4bd04fc7a0236b8]::plumbing::QueryCtxt>>::execute_query
  22:     0x7ff64843160e - <rustc_query_system[caf472e4bac2b2b6]::dep_graph::graph::DepGraph<rustc_middle[1a4ce3311a146f18]::dep_graph::dep_node::DepKind>>::exec_cache_promotions::<rustc_middle[1a4ce3311a146f18]::ty::context::TyCtxt>
  23:     0x7ff648431418 - <rustc_query_impl[a4bd04fc7a0236b8]::on_disk_cache::OnDiskCache as rustc_middle[1a4ce3311a146f18]::ty::context::OnDiskCache>::drop_serialized_data
  24:     0x7ff647e2ed4b - <rustc_session[b87ece769e9b9511]::session::Session>::time::<(), rustc_incremental[80eb23617c4b1afb]::persist::save::save_dep_graph::{closure#0}::{closure#2}::{closure#0}>
  25:     0x7ff647e27b3f - rustc_data_structures[a232da6b1231993b]::sync::join::<rustc_incremental[80eb23617c4b1afb]::persist::save::save_dep_graph::{closure#0}::{closure#2}, rustc_incremental[80eb23617c4b1afb]::persist::save::save_dep_graph::{closure#0}::{closure#3}, (), ()>
  26:     0x7ff647e1e7d7 - <rustc_middle[1a4ce3311a146f18]::dep_graph::dep_node::DepKind as rustc_query_system[caf472e4bac2b2b6]::dep_graph::DepKind>::with_deps::<rustc_incremental[80eb23617c4b1afb]::persist::save::save_dep_graph::{closure#0}, ()>
  27:     0x7ff647e1cf27 - rustc_span[fab0eb11f1fed58d]::with_source_map::<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  28:     0x7ff647e143cc - std[685882fd5f6d52e5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[bd8390756bd7a52a]::util::run_in_thread_pool_with_globals<rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>
  29:     0x7ff647e13dfa - <<std[685882fd5f6d52e5]::thread::Builder>::spawn_unchecked_<rustc_interface[bd8390756bd7a52a]::util::run_in_thread_pool_with_globals<rustc_interface[bd8390756bd7a52a]::interface::run_compiler<core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>, rustc_driver_impl[fb92b3e21ac03dce]::run_compiler::{closure#1}>::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[911a585bea10363d]::result::Result<(), rustc_span[fab0eb11f1fed58d]::ErrorGuaranteed>>::{closure#1} as core[911a585bea10363d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  30:     0x7ff645974593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h39990b24eedef2ab
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
  31:     0x7ff645974593 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h01a027258444143b
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/alloc/src/boxed.rs:1987:9
  32:     0x7ff645974593 - std::sys::unix::thread::Thread::new::thread_start::ha4f1cdd9c25884ba
                               at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/sys/unix/thread.rs:108:17
  33:     0x7ff64570ffd4 - start_thread
                               at ./nptl/./nptl/pthread_create.c:442:8
  34:     0x7ff6457905bc - __GI___clone3
                               at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
  35:                0x0 - <unknown>

error: 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.69.0 (84c898d65 2023-04-16) 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 [has_ffi_unwind_calls] checking if `main` contains FFI-unwind calls
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/ffi_unwind_calls.rs:50:78
stack backtrace:
   0: rust_begin_unwind
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/std/src/panicking.rs:579:5
   1: core::panicking::panic_fmt
             at /rustc/84c898d65adf2f39a5a98507f1fe0ce10a2b8dbc/library/core/src/panicking.rs:64:14
   2: rustc_mir_transform::ffi_unwind_calls::has_ffi_unwind_calls
   3: <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::has_ffi_unwind_calls, rustc_query_impl::plumbing::QueryCtxt>::{closure#1}, bool>
   4: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::queries::has_ffi_unwind_calls, rustc_query_impl::plumbing::QueryCtxt>
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::has_ffi_unwind_calls
   6: <rustc_query_impl::queries::has_ffi_unwind_calls as rustc_query_system::query::config::QueryConfig<rustc_query_impl::plumbing::QueryCtxt>>::execute_query
   7: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::exec_cache_promotions::<rustc_middle::ty::context::TyCtxt>
   8: <rustc_query_impl::on_disk_cache::OnDiskCache as rustc_middle::ty::context::OnDiskCache>::drop_serialized_data
   9: <rustc_session::session::Session>::time::<(), rustc_incremental::persist::save::save_dep_graph::{closure#0}::{closure#2}::{closure#0}>
  10: rustc_data_structures::sync::join::<rustc_incremental::persist::save::save_dep_graph::{closure#0}::{closure#2}, rustc_incremental::persist::save::save_dep_graph::{closure#0}::{closure#3}, (), ()>
  11: <rustc_middle::dep_graph::dep_node::DepKind as rustc_query_system::dep_graph::DepKind>::with_deps::<rustc_incremental::persist::save::save_dep_graph::{closure#0}, ()>
  12: rustc_span::with_source_map::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: 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.69.0 (84c898d65 2023-04-16) 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 [has_ffi_unwind_calls] checking if `main` contains FFI-unwind calls
end of query stack
```

</p>
</details>