rust-lang / rust-lang/rust

ICE: invalid enum variant tag while decoding `MonoItem`

Open
#149,747 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-ICE S-needs-info T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
<extern crate trpl;
use std::time::Duration;
use trpl::Either;

async fn compute_short() -> i32 {
    trpl::sleep(Duration::from_secs(1)).await;
    42
}

async fn compute_long() -> i32 {
    trpl::sleep(Duration::from_secs(3)).await;
    99
}

fn main() {
    trpl::run(async {
        // call a simple async fn and await its result
        let value = compute_short().await;
        println!("compute_short returned: {}", value); // expect 42

        // race compute_long against a timeout of 2 seconds
        match trpl::race(compute_long(), trpl::sleep(Duration::from_secs(2))).await {
            Either::Left(result) => println!("long finished first with {}", result),
            Either::Right(()) => println!("Timed out after 2 seconds"),
        }

        // Bonus race compute_short vs 2s timer => compute_short finished first
        match trpl::race(compute_short(), trpl::sleep(Duration::from_secs(2))).await {
            Either::Left(result) => println!("Short finished first with {}", result),
            Either::Right(()) => println!("Short timed out (unexpected)"),
        }
    });
}
>
Meta

rustc --version --verbose:

<version>
Error output
<admin@MacBook-Pro tiny_async_func % cargo run -q

thread 'rustc' panicked at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/compiler/rustc_middle/src/mir/mono.rs:49:76:
invalid enum variant tag while decoding `MonoItem`, expected 0..3, actual 3
stack backtrace:
   0:        0x10ffd30c0 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h4b01b56329a0a8fc
   1:        0x10d7db0e4 - core::fmt::write::h5ac783d2f16cae69
   2:        0x10ffc6fa4 - std::io::Write::write_fmt::h740ae8bf4425e1f4
   3:        0x10ffd2f80 - std::sys::backtrace::BacktraceLock::print::h822ac0a1da741b33
   4:        0x10ffd54a4 - std::panicking::default_hook::{{closure}}::h182e34e1427a763f
   5:        0x10ffd52a0 - std::panicking::default_hook::hf3c673ab0d652139
   6:        0x10e245f4c - std[c851462af2470259]::panicking::update_hook::<alloc[5a748f96c383aa6f]::boxed::Box<rustc_driver_impl[b0715d04bd56a776]::install_ice_hook::{closure#1}>>::{closure#0}
   7:        0x10ffd5ecc - std::panicking::rust_panic_with_hook::ha68643d4311595e9
   8:        0x10ffd5a38 - std::panicking::begin_panic_handler::{{closure}}::h0edcf2e5c8ce9186
   9:        0x10ffd355c - std::sys::backtrace::__rust_end_short_backtrace::h25049b070cf1a527
  10:        0x10ffd56fc - _rust_begin_unwind
  11:        0x1126a3ce4 - core::panicking::panic_fmt::ha0b5c5252c2f1706
  12:        0x10f62ed18 - <core[5fb0dbaabce25f6b]::iter::adapters::map::Map<core[5fb0dbaabce25f6b]::ops::range::Range<usize>, <[rustc_span[a77c8e897e30def6]::source_map::Spanned<rustc_middle[d103fa9019da59ee]::mir::mono::MonoItem>] as rustc_middle[d103fa9019da59ee]::ty::codec::RefDecodable<rustc_middle[d103fa9019da59ee]::query::on_disk_cache::CacheDecoder>>::decode::{closure#0}> as core[5fb0dbaabce25f6b]::iter::traits::iterator::Iterator>::next
  13:        0x10f6cab94 - <&[rustc_span[a77c8e897e30def6]::source_map::Spanned<rustc_middle[d103fa9019da59ee]::mir::mono::MonoItem>] as rustc_serialize[c6d4baa930e56201]::serialize::Decodable<rustc_middle[d103fa9019da59ee]::query::on_disk_cache::CacheDecoder>>::decode
  14:        0x10f71db24 - <rustc_query_impl[b1806c3197f49f15]::query_impl::items_of_instance::dynamic_query::{closure#6} as core[5fb0dbaabce25f6b]::ops::function::FnOnce<(rustc_middle[d103fa9019da59ee]::ty::context::TyCtxt, &(rustc_middle[d103fa9019da59ee]::ty::instance::Instance, rustc_middle[d103fa9019da59ee]::mir::mono::CollectionMode), rustc_query_system[760a27df5145ae02]::dep_graph::serialized::SerializedDepNodeIndex, rustc_query_system[760a27df5145ae02]::dep_graph::graph::DepNodeIndex)>>::call_once
  15:        0x10f5af6b0 - rustc_query_system[760a27df5145ae02]::query::plumbing::try_execute_query::<rustc_query_impl[b1806c3197f49f15]::DynamicConfig<rustc_query_system[760a27df5145ae02]::query::caches::DefaultCache<(rustc_middle[d103fa9019da59ee]::ty::instance::Instance, rustc_middle[d103fa9019da59ee]::mir::mono::CollectionMode), rustc_middle[d103fa9019da59ee]::query::erase::Erased<[u8; 32usize]>>, false, false, false>, rustc_query_impl[b1806c3197f49f15]::plumbing::QueryCtxt, true>
  16:        0x10f7ee958 - rustc_query_impl[b1806c3197f49f15]::query_impl::items_of_instance::get_query_incr::__rust_end_short_backtrace
  17:        0x10f2007e8 - rustc_monomorphize[9aae175af317f764]::collector::collect_items_rec::{closure#0}
  18:        0x10f1ff0f0 - rustc_monomorphize[9aae175af317f764]::collector::collect_items_rec
  19:        0x10f1fff20 - rustc_monomorphize[9aae175af317f764]::collector::collect_items_rec
  20:        0x10f1fff20 - rustc_monomorphize[9aae175af317f764]::collector::collect_items_rec
  21:        0x10f1fff20 - rustc_monomorphize[9aae175af317f764]::collector::collect_items_rec
  22:        0x10f1fa404 - rustc_monomorphize[9aae175af317f764]::partitioning::collect_and_partition_mono_items
  23:        0x10f77216c - rustc_query_impl[b1806c3197f49f15]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[b1806c3197f49f15]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d103fa9019da59ee]::query::erase::Erased<[u8; 24usize]>>
  24:        0x10f538948 - rustc_query_system[760a27df5145ae02]::query::plumbing::try_execute_query::<rustc_query_impl[b1806c3197f49f15]::DynamicConfig<rustc_query_system[760a27df5145ae02]::query::caches::SingleCache<rustc_middle[d103fa9019da59ee]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[b1806c3197f49f15]::plumbing::QueryCtxt, true>
  25:        0x10f7d5f64 - rustc_query_impl[b1806c3197f49f15]::query_impl::collect_and_partition_mono_items::get_query_incr::__rust_end_short_backtrace
  26:        0x10decc2d8 - rustc_codegen_ssa[b14f965e64741b78]::base::codegen_crate::<rustc_codegen_llvm[8693c5e9711c96e6]::LlvmCodegenBackend>
  27:        0x10dfb3164 - <rustc_codegen_llvm[8693c5e9711c96e6]::LlvmCodegenBackend as rustc_codegen_ssa[b14f965e64741b78]::traits::backend::CodegenBackend>::codegen_crate
  28:        0x10eaaa1dc - <rustc_interface[f03bf5bdfd944c31]::queries::Linker>::codegen_and_build_linker
  29:        0x10e239728 - rustc_interface[f03bf5bdfd944c31]::passes::create_and_enter_global_ctxt::<core[5fb0dbaabce25f6b]::option::Option<rustc_interface[f03bf5bdfd944c31]::queries::Linker>, rustc_driver_impl[b0715d04bd56a776]::run_compiler::{closure#0}::{closure#2}>
  30:        0x10e24c480 - rustc_interface[f03bf5bdfd944c31]::interface::run_compiler::<(), rustc_driver_impl[b0715d04bd56a776]::run_compiler::{closure#0}>::{closure#1}
  31:        0x10e23b1dc - std[c851462af2470259]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f03bf5bdfd944c31]::util::run_in_thread_with_globals<rustc_interface[f03bf5bdfd944c31]::util::run_in_thread_pool_with_globals<rustc_interface[f03bf5bdfd944c31]::interface::run_compiler<(), rustc_driver_impl[b0715d04bd56a776]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  32:        0x10e24f504 - <<std[c851462af2470259]::thread::Builder>::spawn_unchecked_<rustc_interface[f03bf5bdfd944c31]::util::run_in_thread_with_globals<rustc_interface[f03bf5bdfd944c31]::util::run_in_thread_pool_with_globals<rustc_interface[f03bf5bdfd944c31]::interface::run_compiler<(), rustc_driver_impl[b0715d04bd56a776]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[5fb0dbaabce25f6b]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  33:        0x10ffe0eb0 - std::sys::pal::unix::thread::Thread::new::thread_start::hdb877a8060df0ba1
  34:        0x199009c08 - __pthread_cond_wait

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.85.1 (4eb161250 2025-03-15) running on aarch64-apple-darwin

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
panicked at /rustc/4eb161250e340c8f48f66e2b929ef4a5bed7c181/compiler/rustc_query_system/src/dep_graph/graph.rs:1404:5:

thread panicked while processing panic. aborting.
error: could not compile `tiny_async_func` (bin "tiny_async_func")

Caused by:
  process didn't exit successfully: `/Users/admin/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc --crate-name tiny_async_func --edition=2024 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=157 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --check-cfg 'cfg(docsrs,test)' --check-cfg 'cfg(feature, values())' -C metadata=a8e01b0c0de3b26e -C extra-filename=-6db4b02ad1f9fb35 --out-dir /Users/admin/Documents/rust/tiny_async_func/target/debug/deps -C incremental=/Users/admin/Documents/rust/tiny_async_func/target/debug/incremental -L dependency=/Users/admin/Documents/rust/tiny_async_func/target/debug/deps --extern trpl=/Users/admin/Documents/rust/tiny_async_func/target/debug/deps/libtrpl-c2f9304df3cb6e09.rlib -L native=/Users/admin/Documents/rust/tiny_async_func/target/debug/build/ring-e0e614109a72a43d/out` (signal: 6, SIGABRT: process abort signal)
>
Backtrace

<backtrace>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the ICE with the provided async example using cargo run -q, then inspect compiler/rustc_middle/src/mir/mono.rs:49 and the query stack around items_of_instance. The issue is resolved when this input no longer causes rustc to panic while compiling.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.