Repository: rust
Issue: `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))
Labels: I-ICE,T-compiler,C-bug,S-bug-has-test,A-mir-opt-GVN

<!--
[31mICE[0m: Rustc ./a.rs '-Zmir-opt-level=5 --edition=2018 -ooutputfile -Zdump-mir-dir=dir' 'thread 'rustc' panicked at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/compiler/rustc_const_eval/src/interpret/memory.rs:819:80: 'called `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))'', 'thread 'rustc' panicked at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/compiler/rustc_const_eval/src/interpret/memory.rs:819:80: 'called `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))''
File: /tmp/im/a.rs
-->

auto-reduced (treereduce-rust):
````rust
pub enum Request {
    TestSome(T),
}

pub async fn handle_event(event: Request) {
    async move {
        static instance: Request = Request { bar: 17 };
        &instance
    }
    .await;
}


````

original:
````rust
pub enum Request {
    TestSome(T),
}

pub async fn handle_event(
    event: Request,
)  {
    async move {
    static instance: Request = Request { bar: 17 };
    &instance
}.await;
}

pub fn main() {}

````

Version information
````
rustc 1.82.0-nightly (49649bf3c 2024-07-23)
binary: rustc
commit-hash: 49649bf3c5538531ade6834b9b308a6c8a5f3e8e
commit-date: 2024-07-23
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

````

Command:
`/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=5 --edition=2018`

<!--
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>Program output</strong></summary>
<p>

```
error[E0412]: cannot find type `T` in this scope
 --> /tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:2:14
  |
2 |     TestSome(T),
  |              ^ not found in this scope
  |
help: you might be missing a type parameter
  |
1 | pub enum Request<T> {
  |                 +++

error[E0574]: expected struct, variant or union type, found enum `Request`
 --> /tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:7:36
  |
7 |         static instance: Request = Request { bar: 17 };
  |                                    ^^^^^^^ not a struct, variant or union type
  |
help: consider importing this struct instead
  |
1 + use std::error::Request;
  |

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:11:2
   |
11 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs`

warning: unused variable: `event`
 --> /tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:5:27
  |
5 | pub async fn handle_event(event: Request) {
  |                           ^^^^^ help: if this is intentional, prefix it with an underscore: `_event`
  |
  = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/compiler/rustc_const_eval/src/interpret/memory.rs:819:80:
called `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))
stack backtrace:
   0:     0x7aca857e8215 - std::backtrace_rs::backtrace::libunwind::trace::h2d3a238147fe4644
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7aca857e8215 - std::backtrace_rs::backtrace::trace_unsynchronized::h62ccd1746707818d
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7aca857e8215 - std::sys::backtrace::_print_fmt::h198764e2cd3756f6
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/sys/backtrace.rs:65:5
   3:     0x7aca857e8215 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h8efb4db36089f8d1
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/sys/backtrace.rs:40:26
   4:     0x7aca85837c8b - core::fmt::rt::Argument::fmt::h32cf5a418db2846f
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/core/src/fmt/rt.rs:173:76
   5:     0x7aca85837c8b - core::fmt::write::hd634bfe95aa2d191
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/core/src/fmt/mod.rs:1182:21
   6:     0x7aca857dccef - std::io::Write::write_fmt::h18d00a47d2edb63e
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/io/mod.rs:1827:15
   7:     0x7aca857eaa01 - std::sys::backtrace::BacktraceLock::print::hdf53fb28966ef7ad
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/sys/backtrace.rs:43:9
   8:     0x7aca857eaa01 - std::panicking::default_hook::{{closure}}::h6dc27f9ba326a601
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/panicking.rs:269:22
   9:     0x7aca857ea6dc - std::panicking::default_hook::h9dbf01c0a905b2fb
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/panicking.rs:296:9
  10:     0x7aca81c1e709 - std[84685e2f5e49534c]::panicking::update_hook::<alloc[69d17d5c7a222efa]::boxed::Box<rustc_driver_impl[2ca809430a6bb1db]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7aca857eb3cf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h2926931e5fae8e54
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/alloc/src/boxed.rs:2163:9
  12:     0x7aca857eb3cf - std::panicking::rust_panic_with_hook::ha943b79683377534
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/panicking.rs:808:13
  13:     0x7aca857eaff7 - std::panicking::begin_panic_handler::{{closure}}::hb948fc2cd41a6d5c
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/panicking.rs:674:13
  14:     0x7aca857e86d9 - std::sys::backtrace::__rust_end_short_backtrace::h82feed5209c926ba
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/sys/backtrace.rs:168:18
  15:     0x7aca857eac84 - rust_begin_unwind
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/panicking.rs:665:5
  16:     0x7aca85834243 - core::panicking::panic_fmt::ha0806b6370825159
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/core/src/panicking.rs:74:14
  17:     0x7aca85834896 - core::result::unwrap_failed::h4fc72d8e11c69246
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/core/src/result.rs:1679:5
  18:     0x7aca84a6478f - <rustc_const_eval[bdbbaff3c31c13f6]::interpret::eval_context::InterpCx<rustc_const_eval[bdbbaff3c31c13f6]::const_eval::dummy_machine::DummyMachine>>::get_alloc_info.cold
  19:     0x7aca83cf0dfa - <rustc_const_eval[bdbbaff3c31c13f6]::interpret::eval_context::InterpCx<rustc_const_eval[bdbbaff3c31c13f6]::const_eval::dummy_machine::DummyMachine>>::scalar_may_be_null
  20:     0x7aca83cf08a4 - <rustc_const_eval[bdbbaff3c31c13f6]::interpret::eval_context::InterpCx<rustc_const_eval[bdbbaff3c31c13f6]::const_eval::dummy_machine::DummyMachine>>::read_discriminant::<rustc_const_eval[bdbbaff3c31c13f6]::interpret::operand::OpTy>
  21:     0x7aca83ce8cee - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::VnState>::insert
  22:     0x7aca83ce2524 - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::VnState>::simplify_rvalue
  23:     0x7aca80d2d468 - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::GVN as rustc_middle[f06a2f49cb923fa3]::mir::MirPass>::run_pass
  24:     0x7aca83201c7b - rustc_mir_transform[48c5b07b6fa30cb7]::pass_manager::run_passes_inner
  25:     0x7aca837d9256 - rustc_mir_transform[48c5b07b6fa30cb7]::optimized_mir
  26:     0x7aca8409185d - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>
  27:     0x7aca8348a857 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::DefIdCache<rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  28:     0x7aca8348a034 - rustc_query_impl[3f261a864a124585]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  29:     0x7aca833b2457 - rustc_middle[f06a2f49cb923fa3]::query::plumbing::query_get_at::<rustc_query_system[85f7d4985ebc0774]::query::caches::DefIdCache<rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>>
  30:     0x7aca82209fc0 - <rustc_middle[f06a2f49cb923fa3]::ty::context::TyCtxt>::coroutine_layout
  31:     0x7aca838254e2 - rustc_ty_utils[4b3be0d27c5e9905]::layout::layout_of_uncached
  32:     0x7aca8381444b - rustc_ty_utils[4b3be0d27c5e9905]::layout::layout_of
  33:     0x7aca838143d1 - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 16usize]>>
  34:     0x7aca838136d0 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::DefaultCache<rustc_middle[f06a2f49cb923fa3]::ty::ParamEnvAnd<rustc_middle[f06a2f49cb923fa3]::ty::Ty>, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  35:     0x7aca8381336f - rustc_query_impl[3f261a864a124585]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7aca83ce6a56 - rustc_middle[f06a2f49cb923fa3]::query::plumbing::query_get_at::<rustc_query_system[85f7d4985ebc0774]::query::caches::DefaultCache<rustc_middle[f06a2f49cb923fa3]::ty::ParamEnvAnd<rustc_middle[f06a2f49cb923fa3]::ty::Ty>, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 16usize]>>>
  37:     0x7aca83ce824e - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::VnState>::insert
  38:     0x7aca83ce2524 - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::VnState>::simplify_rvalue
  39:     0x7aca80d2d468 - <rustc_mir_transform[48c5b07b6fa30cb7]::gvn::GVN as rustc_middle[f06a2f49cb923fa3]::mir::MirPass>::run_pass
  40:     0x7aca83201c7b - rustc_mir_transform[48c5b07b6fa30cb7]::pass_manager::run_passes_inner
  41:     0x7aca837d9256 - rustc_mir_transform[48c5b07b6fa30cb7]::optimized_mir
  42:     0x7aca8409185d - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7aca8348a857 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::DefIdCache<rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  44:     0x7aca8348a034 - rustc_query_impl[3f261a864a124585]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7aca833b2457 - rustc_middle[f06a2f49cb923fa3]::query::plumbing::query_get_at::<rustc_query_system[85f7d4985ebc0774]::query::caches::DefIdCache<rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>>
  46:     0x7aca82209fc0 - <rustc_middle[f06a2f49cb923fa3]::ty::context::TyCtxt>::coroutine_layout
  47:     0x7aca838254e2 - rustc_ty_utils[4b3be0d27c5e9905]::layout::layout_of_uncached
  48:     0x7aca8381444b - rustc_ty_utils[4b3be0d27c5e9905]::layout::layout_of
  49:     0x7aca838143d1 - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 16usize]>>
  50:     0x7aca838136d0 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::DefaultCache<rustc_middle[f06a2f49cb923fa3]::ty::ParamEnvAnd<rustc_middle[f06a2f49cb923fa3]::ty::Ty>, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  51:     0x7aca8381336f - rustc_query_impl[3f261a864a124585]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7aca808e0b67 - <rustc_mir_transform[48c5b07b6fa30cb7]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[48c5b07b6fa30cb7]::pass_manager::MirLint>::run_lint
  53:     0x7aca83201c7b - rustc_mir_transform[48c5b07b6fa30cb7]::pass_manager::run_passes_inner
  54:     0x7aca83a13f29 - rustc_mir_transform[48c5b07b6fa30cb7]::mir_drops_elaborated_and_const_checked
  55:     0x7aca83a137fd - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>
  56:     0x7aca834b0eb3 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::VecCache<rustc_span[b5058cd9cdbacc64]::def_id::LocalDefId, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  57:     0x7aca834b0859 - rustc_query_impl[3f261a864a124585]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  58:     0x7aca83a20318 - rustc_interface[4a5f03b368ced297]::passes::analysis
  59:     0x7aca83a1f21b - rustc_query_impl[3f261a864a124585]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3f261a864a124585]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 1usize]>>
  60:     0x7aca840d96a5 - rustc_query_system[85f7d4985ebc0774]::query::plumbing::try_execute_query::<rustc_query_impl[3f261a864a124585]::DynamicConfig<rustc_query_system[85f7d4985ebc0774]::query::caches::SingleCache<rustc_middle[f06a2f49cb923fa3]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3f261a864a124585]::plumbing::QueryCtxt, false>
  61:     0x7aca840d940f - rustc_query_impl[3f261a864a124585]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  62:     0x7aca83fce6c5 - rustc_interface[4a5f03b368ced297]::interface::run_compiler::<core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>, rustc_driver_impl[2ca809430a6bb1db]::run_compiler::{closure#0}>::{closure#1}
  63:     0x7aca83fb51c9 - std[84685e2f5e49534c]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4a5f03b368ced297]::util::run_in_thread_with_globals<rustc_interface[4a5f03b368ced297]::util::run_in_thread_pool_with_globals<rustc_interface[4a5f03b368ced297]::interface::run_compiler<core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>, rustc_driver_impl[2ca809430a6bb1db]::run_compiler::{closure#0}>::{closure#1}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>::{closure#0}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>
  64:     0x7aca83fb4f7a - <<std[84685e2f5e49534c]::thread::Builder>::spawn_unchecked_<rustc_interface[4a5f03b368ced297]::util::run_in_thread_with_globals<rustc_interface[4a5f03b368ced297]::util::run_in_thread_pool_with_globals<rustc_interface[4a5f03b368ced297]::interface::run_compiler<core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>, rustc_driver_impl[2ca809430a6bb1db]::run_compiler::{closure#0}>::{closure#1}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>::{closure#0}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[c37d915429d9bf38]::result::Result<(), rustc_span[b5058cd9cdbacc64]::ErrorGuaranteed>>::{closure#1} as core[c37d915429d9bf38]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  65:     0x7aca857f542b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hb5e78d42d6801749
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/alloc/src/boxed.rs:2149:9
  66:     0x7aca857f542b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hd9416e19f44d968d
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/alloc/src/boxed.rs:2149:9
  67:     0x7aca857f542b - std::sys::pal::unix::thread::Thread::new::thread_start::he0388d99656ed7ca
                               at /rustc/49649bf3c5538531ade6834b9b308a6c8a5f3e8e/library/std/src/sys/pal/unix/thread.rs:108:17
  68:     0x7aca7e6a6ded - <unknown>
  69:     0x7aca7e72a0dc - <unknown>
  70:                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: please make sure that you have updated to the latest nightly

note: rustc 1.82.0-nightly (49649bf3c 2024-07-23) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=5 -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `handle_event::{closure#0}::{closure#0}`
#1 [layout_of] computing layout of `{async block@/tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:6:5: 6:15}`
end of query stack
error: aborting due to 3 previous errors; 1 warning emitted

Some errors have detailed explanations: E0412, E0574, E0601.
For more information about an error, try `rustc --explain E0412`.

```

</p>
</details>

<!--
query stack:
#0 [optimized_mir] optimizing MIR for `handle_event::{closure#0}::{closure#0}`
#1 [layout_of] computing layout of `{async block@/tmp/icemaker_global_tempdir.7wIEjd0lKecw/rustc_testrunner_tmpdir_reporting.168IfbM3nYxW/mvce.rs:6:5: 6:15}`

-->