rust-lang / rust-lang/rust

Unexpected initial operand type

Open
#155,310 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-async_drop F-coroutines needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I tried this code:

#![feature(async_drop)]
#![feature(coroutines)]
pub fn main() {
  async {
#[coroutine]
    || yield;
  };
}

rustc code.rs --edition=2024 -Clink-dead-code

  WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type:
 expected (),
 found    &'{erased} mut std::task::Context<'{erased}>.
 See <https://github.com/rust-lang/rust/issues/114858>.
Meta

rustc --version --verbose:

rustc 1.97.0-nightly (17584a181 2026-04-13)
binary: rustc
commit-hash: 17584a181979f04f2aaad867332c22db1caa511a
commit-date: 2026-04-13
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.2

Note adding -Zcodegen-backend=cranelift turns it into an ice

Backtrace

thread 'rustc' (1163411) panicked at /rustc-dev/17584a181979f04f2aaad867332c22db1caa511a/compiler/rustc_codegen_cranelift/src/value_and_place.rs:510:9:
assertion `left == right` failed: Can't write value with incompatible type &'{erased} mut std::task::Context<'{erased}> to place with type ()

[Coroutine(DefId(0:5 ~ code[5fe1]::main::{closure#0}::{closure#0}), [(), (), (), (), ()]), (), std::future::ResumeTy, (), (), (*mut Coroutine(DefId(0:5 ~ code[5fe1]::main::{closure#0}::{closure#0}), [(), (), (), (), ()]),)]
[CPlace { inner: Addr(Pointer { base: Stack(ss0), offset: Offset32(0) }, None), layout: TyAndLayout { ty: Poll<()>, layout: Layout { size: Size(1 bytes), align: AbiAlign { abi: Align(1 bytes) }, backend_repr: Scalar(Initialized { value: Int(I8, false), valid_range: 0..=1 }), fields: Arbitrary { offsets: [Size(0 bytes)], in_memory_order: [0] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Int(I8, false), valid_range: 0..=1 }), uninhabited: false, variants: Multiple { tag: Initialized { value: Int(I8, false), valid_range: 0..=1 }, tag_encoding: Direct, tag_field: 0, variants: [Layout { size: Size(1 bytes), align: AbiAlign { abi: Align(1 bytes) }, backend_repr: Scalar(Initialized { value: Int(I8, false), valid_range: 0..=1 }), fields: Arbitrary { offsets: [Size(1 bytes)], in_memory_order: [0] }, largest_niche: None, uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), randomization_seed: 6371488611584763486 }, Layout { size: Size(1 bytes), align: AbiAlign { abi: Align(1 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [], in_memory_order: [] }, largest_niche: None, uninhabited: false, variants: Single { index: 1 }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), randomization_seed: 6371488611584763486 }] }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), randomization_seed: 667721761044738842 } } }, CPlace { inner: Addr(Pointer { base: Stack(ss1), offset: Offset32(0) }, None), layout: TyAndLayout { ty: Pin<&mut {async fn body of async_drop_in_place<{coroutine@code.rs:6:5: 6:7}>()}>, layout: Layout { size: Size(8 bytes), align: AbiAlign { abi: Align(8 bytes) }, backend_repr: Scalar(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), fields: Arbitrary { offsets: [Size(0 bytes)], in_memory_order: [0] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 18365188995968913426 } } }, CPlace { inner: Addr(Pointer { base: Dangling(Align(1 bytes)), offset: Offset32(0) }, None), layout: TyAndLayout { ty: (), layout: Layout { size: Size(0 bytes), align: AbiAlign { abi: Align(1 bytes) }, backend_repr: Memory { sized: true }, fields: Arbitrary { offsets: [], in_memory_order: [] }, largest_niche: None, uninhabited: false, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), randomization_seed: 0 } } }]

function u0:7(i64, i64) -> i8 uext system_v {
    ss0 = explicit_slot 1
    ss1 = explicit_slot 8, align = 8

block0(v0: i64, v1: i64):
    nop
    stack_store v0, ss1
}


  left: &'{erased} mut std::task::Context<'{erased}>
 right: ()
stack backtrace:
   0:     0x7f30ab4129bb - <<std[82445d07c273dcb0]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[e6c15338c37dc114]::fmt::Display>::fmt
   1:     0x7f30aba21748 - core[e6c15338c37dc114]::fmt::write
   2:     0x7f30ab429c86 - <std[82445d07c273dcb0]::sys::stdio::unix::Stderr as std[82445d07c273dcb0]::io::Write>::write_fmt
   3:     0x7f30ab3e8cb8 - std[82445d07c273dcb0]::panicking::default_hook::{closure#0}
   4:     0x7f30ab406023 - std[82445d07c273dcb0]::panicking::default_hook
   5:     0x7f30aa3e16ec - std[82445d07c273dcb0]::panicking::update_hook::<alloc[8aa01d6867f017eb]::boxed::Box<rustc_driver_impl[b53ec1d8796d19d7]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f30ab406302 - std[82445d07c273dcb0]::panicking::panic_with_hook
   7:     0x7f30ab3e8d78 - std[82445d07c273dcb0]::panicking::panic_handler::{closure#0}
   8:     0x7f30ab3dd2d9 - std[82445d07c273dcb0]::sys::backtrace::__rust_end_short_backtrace::<std[82445d07c273dcb0]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f30ab3ea7dd - __rustc[ccd49f7a2776e796]::rust_begin_unwind
  10:     0x7f30a7f5bdec - core[e6c15338c37dc114]::panicking::panic_fmt
  11:     0x7f30a9c8a893 - core[e6c15338c37dc114]::panicking::assert_failed_inner
  12:     0x7f30aaa00547 - core[e6c15338c37dc114]::panicking::assert_failed::<rustc_middle[f0f16db128b18e3d]::ty::Ty, rustc_middle[f0f16db128b18e3d]::ty::Ty>
  13:     0x7f3098eaeb9e - rustc_codegen_cranelift[c4ed53a42162c0ac]::value_and_place::assert_assignable
  14:     0x7f3098ebd481 - rustc_codegen_cranelift[c4ed53a42162c0ac]::base::codegen_fn_body
  15:     0x7f3098ee796d - rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::codegen_cgu_content
  16:     0x7f3098e81cec - rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::run_aot::{closure#3}::{closure#0}::{closure#0}
  17:     0x7f3098e82e12 - rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::run_aot::{closure#3}::{closure#0}
  18:     0x7f3098ef4a69 - <core[e6c15338c37dc114]::iter::adapters::filter_map::FilterMap<alloc[8aa01d6867f017eb]::vec::into_iter::IntoIter<(usize, &rustc_middle[f0f16db128b18e3d]::mono::CodegenUnit)>, rustc_data_structures[89e4a6a540cc2895]::sync::parallel::par_map<(usize, &rustc_middle[f0f16db128b18e3d]::mono::CodegenUnit), alloc[8aa01d6867f017eb]::vec::Vec<(usize, &rustc_middle[f0f16db128b18e3d]::mono::CodegenUnit)>, rustc_data_structures[89e4a6a540cc2895]::marker::IntoDynSyncSend<rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::OngoingModuleCodegen>, alloc[8aa01d6867f017eb]::vec::Vec<rustc_data_structures[89e4a6a540cc2895]::marker::IntoDynSyncSend<rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::OngoingModuleCodegen>>, rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::run_aot::{closure#3}::{closure#0}>::{closure#0}::{closure#3}> as core[e6c15338c37dc114]::iter::traits::iterator::Iterator>::next
  19:     0x7f3098eec828 - rustc_codegen_cranelift[c4ed53a42162c0ac]::driver::aot::run_aot
  20:     0x7f3098efea05 - <rustc_codegen_cranelift[c4ed53a42162c0ac]::CraneliftCodegenBackend as rustc_codegen_ssa[ebd0a9eafe8c53bd]::traits::backend::CodegenBackend>::codegen_crate
  21:     0x7f30acb904b2 - <rustc_interface[36da19b6867c2d6b]::queries::Linker>::codegen_and_build_linker
  22:     0x7f30acb8a709 - rustc_interface[36da19b6867c2d6b]::interface::run_compiler::<(), rustc_driver_impl[b53ec1d8796d19d7]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7f30acbaa2be - std[82445d07c273dcb0]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[36da19b6867c2d6b]::util::run_in_thread_with_globals<rustc_interface[36da19b6867c2d6b]::util::run_in_thread_pool_with_globals<rustc_interface[36da19b6867c2d6b]::interface::run_compiler<(), rustc_driver_impl[b53ec1d8796d19d7]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  24:     0x7f30acbaab60 - <std[82445d07c273dcb0]::thread::lifecycle::spawn_unchecked<rustc_interface[36da19b6867c2d6b]::util::run_in_thread_with_globals<rustc_interface[36da19b6867c2d6b]::util::run_in_thread_pool_with_globals<rustc_interface[36da19b6867c2d6b]::interface::run_compiler<(), rustc_driver_impl[b53ec1d8796d19d7]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[e6c15338c37dc114]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f30acbab9ec - <std[82445d07c273dcb0]::sys::thread::unix::Thread>::new::thread_start
  26:     0x7f30a66a597a - <unknown>
  27:     0x7f30a67292bc - <unknown>
  28:                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: please attach the file at `/home/matthias/vcs/github/CRED/rustc-ice-2026-04-14T20_36_29-1163401.txt` to your bug report

note: rustc 1.97.0-nightly (17584a181 2026-04-13) running on x86_64-unknown-linux-gnu

note: compiler flags: -C link-dead-code -Z codegen-backend=cranelift

query stack during panic:
end of query stack
fn std::future::async_drop_in_place::{closure#0}(_1: std::pin::Pin<&mut {async fn body of std::future::async_drop_in_place<{coroutine@code.rs:6:5: 6:7}>()}>, _2: ()) -> std::task::Poll<()> {
    let mut _0: std::task::Poll<()>;
    let mut _3: &mut {async fn body of std::future::async_drop_in_place<{coroutine@code.rs:6:5: 6:7}>()};
    let mut _4: *mut {coroutine@code.rs:6:5: 6:7};
    let mut _5: *const ();
    let mut _6: usize;
    let mut _7: usize;
    let mut _8: usize;
    let mut _9: bool;
    let mut _10: *const ();
    let mut _11: usize;
    let mut _12: bool;
    let mut _13: bool;
    let mut _14: bool;

    bb0: {
        _3 = copy (_1.0: &mut {async fn body of std::future::async_drop_in_place<{coroutine@code.rs:6:5: 6:7}>()});
        _4 = copy ((*_3).0: *mut {coroutine@code.rs:6:5: 6:7});
        _5 = copy _4 as *const () (PtrToPtr);
        _6 = copy _5 as usize (Transmute);
        _7 = Sub(const <{coroutine@code.rs:6:5: 6:7} as std::mem::SizedTypeProperties>::ALIGN, const 1_usize);
        _8 = BitAnd(copy _6, copy _7);
        _9 = Eq(copy _8, const 0_usize);
        assert(copy _9, "misaligned pointer dereference: address must be a multiple of {} but is {}", const <{coroutine@code.rs:6:5: 6:7} as std::mem::SizedTypeProperties>::ALIGN, copy _6) -> [success: bb1, unwind unreachable];
    }

    bb1: {
        _10 = copy _4 as *const () (PtrToPtr);
        _11 = copy _10 as usize (Transmute);
        _12 = Eq(copy _11, const 0_usize);
        _13 = BitAnd(copy _12, const true);
        _14 = Not(copy _13);
        assert(copy _14, "null pointer dereference occurred") -> [success: bb2, unwind unreachable];
    }

    bb2: {
        _0 = std::task::Poll::<()>::Ready(const ());
        return;
    }
}

bisects to nightly-2025-04-29, probably #123948

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

Reproduce the report with the async-drop and coroutine example, first comparing the normal compiler warning with the Cranelift ICE. Then inspect rustc_codegen_cranelift/src/value_and_place.rs:510 and the codegen_fn_body path shown in the backtrace, using the nightly-2025-04-29 bisect and issue #114858 as context. Done means the reproducer no longer reports the incompatible operand or panics.

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
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.