Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE:called Result::unwrap() on an Err value: ReferencesError(ErrorGuaranteed(())) #138225

Open
sososopy opened this issue Mar 8, 2025 · 2 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@sososopy
Copy link

sososopy commented Mar 8, 2025

Similar to problem #128094, it may be a duplicate problem, but the compile command is different
The issue compilation command I opened is -C opt-level=1, and #128094 is -Zmir-opt-level=5 --edition=2018

And the code is a little different, so I brought up the issue

Code

pub struct A {
    name:NestedOption<Option<String>>,
}
impl<'a> A {
    pub async fn func1(
    ) -> &'static A {
        static res: A =
            A { name: None };
        &res
    }
}
fn main() {}

Meta

rustc --version --verbose:

rustc 1.87.0-nightly (f5a1ef712 2025-03-07)
binary: rustc
commit-hash: f5a1ef7121ad661b5a21a1d02941c8064d54ee0b
commit-date: 2025-03-07
host: x86_64-pc-windows-msvc
release: 1.87.0-nightly
LLVM version: 20.1.0

Error output

error[E0670]: `async fn` is not permitted in Rust 2015
   --> .\ttt\test.rs:165:9
    |
165 |     pub async fn func1(
    |         ^^^^^ to use `async fn`, switch to Rust 2018 or later
    |
    = help: pass `--edition 2024` to `rustc`
    = note: for more on editions, read https://doc.rust-lang.org/edition-guide

error[E0412]: cannot find type `NestedOption` in this scope
   --> .\ttt\test.rs:162:10
    |
162 |     name:NestedOption<Option<String>>,
    |          ^^^^^^^^^^^^ not found in this scope
Backtrace

thread 'rustc' panicked at compiler\rustc_middle\src\mir\interpret\mod.rs:371:79:
called `Result::unwrap()` on an `Err` value: ReferencesError(ErrorGuaranteed(()))
stack backtrace:
   0:     0x7ff835466c63 - std::backtrace_rs::backtrace::win64::trace
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\..\..\backtrace\src\backtrace\win64.rs:85
   1:     0x7ff835466c63 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff835466c63 - std::sys::backtrace::_print_fmt
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\sys\backtrace.rs:66
   3:     0x7ff835466c63 - std::sys::backtrace::impl$0::print::impl$0::fmt
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\sys\backtrace.rs:39
   4:     0x7ff83549a02a - core::fmt::rt::Argument::fmt
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\core\src\fmt\rt.rs:177
   5:     0x7ff83549a02a - core::fmt::write
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\core\src\fmt\mod.rs:1449
   6:     0x7ff83545c9d7 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\io\mod.rs:1890
   7:     0x7ff835466aa5 - std::sys::backtrace::BacktraceLock::print
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\sys\backtrace.rs:42
   8:     0x7ff83546ae19 - std::panicking::default_hook::closure$0
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\panicking.rs:298
   9:     0x7ff83546ac08 - std::panicking::default_hook
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\panicking.rs:325
  10:     0x7ff8369ff347 - core[a49717954fd349d5]::slice::sort::unstable::heapsort::heapsort::<((rustc_lint_defs[c763add0498415dc]::Level, &str), usize), <((rustc_lint_defs[c763add0498415dc]::Level, &str), usize) as core[a49717954fd349d5]::cmp::PartialOrd>::lt>
  11:     0x7ff83546baae - std::panicking::rust_panic_with_hook
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\panicking.rs:839
  12:     0x7ff83546b809 - std::panicking::begin_panic_handler::closure$0
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\panicking.rs:704
  13:     0x7ff83546775f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\sys\backtrace.rs:168
  14:     0x7ff83546b40e - std::panicking::begin_panic_handler
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\panicking.rs:695
  15:     0x7ff8382c8bf1 - core::panicking::panic_fmt
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\core\src\panicking.rs:75
  16:     0x7ff8382c91e0 - core::result::unwrap_failed
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\core\src\result.rs:1704
  17:     0x7ff83682c3e4 - <rustc_middle[a635f052194163b9]::mir::interpret::GlobalAlloc>::size_and_align
  18:     0x7ff834d54aa9 - <alloc[fd90ba3301162542]::raw_vec::RawVec<(rustc_middle[a635f052194163b9]::mir::Location, rustc_middle[a635f052194163b9]::mir::statement::Statement)>>::grow_one
  19:     0x7ff837038d8e - <std[d7b13ccbece4c715]::io::buffered::bufwriter::BufWriter<std[d7b13ccbece4c715]::fs::File>>::write_cold
  20:     0x7ff834d3bc35 - RINvNtNtNtNtCse86O2quqQfh_4core5slice4sort6stable9quicksort9quicksortNtNtNtCsegJBPcicXKD_12rustc_middle3mir4mono11CodegenUnitNCINvMNtCslLIMKTelctO_5alloc5sliceSB15_7sort_byNCNvNtCs9o0KB2sPaJH_18rustc_monomorphize12partitioning19merge_codegen_unitss4_0E0EB2
  21:     0x7ff8359b7780 - <rustc_mir_transform[40bbba604935fcaa]::inline::NormalInliner as rustc_mir_transform[40bbba604935fcaa]::inline::Inliner>::check_callee_mir_body
  22:     0x7ff8359ada52 - <rustc_mir_transform[40bbba604935fcaa]::inline::NormalInliner as rustc_mir_transform[40bbba604935fcaa]::inline::Inliner>::check_callee_mir_body
  23:     0x7ff8359c3246 - <rustc_mir_transform[40bbba604935fcaa]::gvn::GVN as rustc_mir_transform[40bbba604935fcaa]::pass_manager::MirPass>::run_pass
  24:     0x7ff8358a65d1 - <rustc_mir_transform[40bbba604935fcaa]::simplify::SimplifyCfg as rustc_mir_transform[40bbba604935fcaa]::pass_manager::MirPass>::run_pass
  25:     0x7ff8358d8560 - rustc_mir_transform[40bbba604935fcaa]::optimized_mir
  26:     0x7ff83620b210 - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  27:     0x7ff8360f179e - RINvNtNtCs9HWllMiJxcJ_18rustc_query_system5query8plumbing17try_execute_queryINtCsfG0cl2i4BMx_16rustc_query_impl13DynamicConfigINtNtB4_6caches10DefIdCacheINtNtNtCsegJBPcicXKD_12rustc_middle5query5erase6ErasedAhj8_EEKb0_KB3r_KB3r_ENtNtB1f_8plumbing9QueryCtxt
  28:     0x7ff836211565 - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  29:     0x7ff8368e0b21 - <rustc_middle[a635f052194163b9]::query::on_disk_cache::CacheEncoder as rustc_span[8d7f1e951f109c7b]::SpanEncoder>::encode_def_id
  30:     0x7ff83800c3d7 - <rustc_middle[a635f052194163b9]::ty::context::TyCtxt>::coroutine_layout
  31:     0x7ff83608b6a3 - rustc_ty_utils[d76525a50ceaca42]::instance::resolve_instance_raw
  32:     0x7ff8360a537c - rustc_ty_utils[d76525a50ceaca42]::layout::layout_of
  33:     0x7ff83620d03e - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  34:     0x7ff83610e0e9 - RINvNtNtCs9HWllMiJxcJ_18rustc_query_system5query8plumbing17try_execute_queryINtCsfG0cl2i4BMx_16rustc_query_impl13DynamicConfigINtNtB4_6caches12DefaultCacheINtNtCsegJBPcicXKD_12rustc_middle2ty20PseudoCanonicalInputNtB2w_2TyEINtNtNtB2y_5query5erase6ErasedAhj
  35:     0x7ff83621a46c - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  36:     0x7ff835920afa - <rustc_mir_transform[40bbba604935fcaa]::known_panics_lint::KnownPanicsLint as rustc_mir_transform[40bbba604935fcaa]::pass_manager::MirLint>::run_lint
  37:     0x7ff8358d2e84 - rustc_mir_transform[40bbba604935fcaa]::run_analysis_to_runtime_passes
  38:     0x7ff8358ce9b0 - rustc_mir_transform[40bbba604935fcaa]::mir_drops_elaborated_and_const_checked
  39:     0x7ff83620cb1b - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  40:     0x7ff836156051 - RINvNtNtCs9HWllMiJxcJ_18rustc_query_system5query8plumbing17try_execute_queryINtCsfG0cl2i4BMx_16rustc_query_impl13DynamicConfigINtNtCsfSfDFhv6ONJ_21rustc_data_structures9vec_cache8VecCacheNtNtCsc9bkXepKnRD_10rustc_span6def_id10LocalDefIdINtNtNtCsegJBPcicXKD
  41:     0x7ff836211263 - rustc_query_impl[b69aee932fe91357]::plumbing::query_key_hash_verify_all
  42:     0x7ff8354e40c4 - rustc_interface[ee21df1734f8ab0f]::passes::resolver_for_lowering_raw
  43:     0x7ff831e48479 - rustc_interface[ee21df1734f8ab0f]::passes::analysis
  44:     0x7ff834fe6baa - <alloc[fd90ba3301162542]::sync::Arc<rustc_session[8146d5d0b944a82b]::config::OutputFilenames>>::drop_slow
  45:     0x7ff834ef46a4 - RINvNtNtCs9HWllMiJxcJ_18rustc_query_system5query8plumbing17try_execute_queryINtCsfG0cl2i4BMx_16rustc_query_impl13DynamicConfigINtNtB4_6caches11SingleCacheINtNtNtCsegJBPcicXKD_12rustc_middle5query5erase6ErasedAhj0_EEKb0_KB3s_KB3s_ENtNtB1f_8plumbing9QueryCtx
  46:     0x7ff834fec6a4 - rustc_query_impl[b69aee932fe91357]::query_system
  47:     0x7ff831e0dcd2 - RINvNtNtCsiw7LomwTgZ5_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCslLIMKTelctO_5alloc5boxed3BoxDINtNtNtCse86O2quqQfh_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECsbsz
  48:     0x7ff831e06264 - RINvNtNtCsiw7LomwTgZ5_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCslLIMKTelctO_5alloc5boxed3BoxDINtNtNtCse86O2quqQfh_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECsbsz
  49:     0x7ff831dfef03 - RINvNtNtCsiw7LomwTgZ5_3std3sys9backtrace28___rust_begin_short_backtraceNCNCINvNtCskrzvsuieKkd_15rustc_interface4util26run_in_thread_with_globalsNCINvB1e_31run_in_thread_pool_with_globalsNCINvNtB1g_9interface12run_compileruNCNvCsbsz2LbB1MIu_17rustc_driver_i
  50:     0x7ff831e12ed0 - RINvNtNtCsiw7LomwTgZ5_3std3sys9backtrace28___rust_begin_short_backtraceNCNCNCINvMNtB6_6threadNtB1h_7Builder16spawn_unchecked_INtNtCslLIMKTelctO_5alloc5boxed3BoxDINtNtNtCse86O2quqQfh_4core3ops8function6FnOnceuEp6OutputuNtNtB2G_6marker4SendEL_EuEs_000uECsbsz
  51:     0x7ff83547c23d - alloc::boxed::impl$28::call_once
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\alloc\src\boxed.rs:1970
  52:     0x7ff83547c23d - alloc::boxed::impl$28::call_once
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\alloc\src\boxed.rs:1970
  53:     0x7ff83547c23d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/f5a1ef7121ad661b5a21a1d02941c8064d54ee0b/library\std\src\sys\pal\windows\thread.rs:56
  54:     0x7ff8f6c87374 - BaseThreadInitThunk
  55:     0x7ff8f777cc91 - RtlUserThreadStart

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: please attach the file at `D:\rust_test\test1\src\rustc-ice-2025-03-08T13_01_27-29596.txt` to your bug report

note: compiler flags: -C opt-level=1

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at .\ttt\test.rs:164:1: 164:11>::func1::{closure#0}`
#1 [layout_of] computing layout of `{async fn body of <impl at .\ttt\test.rs:164:1: 164:11>::func1()}`
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack

@sososopy sososopy added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 8, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 8, 2025
@matthiaskrgr
Copy link
Member

The flags do not make a difference here I think as both snippets crash with opt-level-1 and mir-opt-level=5
My guess is that in both cases we enable the GVN mir opt which then causes the underlying problem.

@sososopy
Copy link
Author

sososopy commented Mar 8, 2025

pub struct A {
    name:Option<String>,
}
impl<'a> A {
    pub async fn func1(
    ) -> &'static A {
        static res: A =
            A { name: None };
        &res
    }
}
fn main() {}

I don't understand why struct members change to this way and it doesn't generate ICE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants