rust-lang / rust-lang/rust

[ICE]: delayed bug in fully_perform + broken MIR when AsyncFnMut(&()) is cast to FnMut(&())

Open
#159,286 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-async-closures A-higher-ranked C-bug fixed-by-next-solver I-ICE T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code
struct Wrapper<F>(F);

fn wrap<F: AsyncFnMut(&())>(f: F) -> Wrapper<F> {
    Wrapper(f)
}

trait Trait {
    type Assoc;
    fn method(self) -> Self::Assoc;
}

trait Trait2 {}

impl<F: Trait2> Trait for F {
    type Assoc = ();
    fn method(self) -> Self::Assoc {
        loop {}
    }
}

impl<F: FnMut(&()) -> Fut, Fut> Trait for Wrapper<F> {
    type Assoc = ();
    fn method(self) -> Self::Assoc {
        loop {}
    }
}

fn main() {
    wrap(async |_| {}).method();
}

Playground

It errors out in fully_perform without an associated type as well, but the broken MIR error doesn't appear, so I kept it just in case.

Meta

rustc --version --verbose:

rustc 1.99.0-nightly (3659db0d3 2026-07-05)
binary: rustc
commit-hash: 3659db0d3e2cd634c766fcda79ed118eca31a9fd
commit-date: 2026-07-05
host: x86_64-unknown-linux-gnu
release: 1.99.0-nightly
LLVM version: 22.1.8

Reproduces on stable as well.

Error output
note: no errors encountered even though delayed bugs were created

note: those delayed bugs will now be shown as internal compiler errors

error: internal compiler error: error performing operation: fully_perform
  --> ydb/examples/topic-read-in-transaction-example.rs:29:5
   |
29 |     wrap(async |_| {}).method();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: delayed at /rustc-dev/3659db0d3e2cd634c766fcda79ed118eca31a9fd/compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs:126:26 - disabled backtrace
  --> ydb/examples/topic-read-in-transaction-example.rs:29:5
   |
29 |     wrap(async |_| {}).method();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: internal compiler error: broken MIR in DefId(0:22 ~ topic_read_in_transaction_example[dee8]::main) (_1 = <Wrapper<{async closure@ydb/examples/topic-read-in-transaction-example.rs:29:10: 29:19}> as Trait>::method(move _2) -> [return: bb2, unwind: bb3]): call dest mismatch (() <- Alias(No, Alias { kind: Projection { def_id: DefId(0:10 ~ topic_read_in_transaction_example[dee8]::Trait::Assoc) }, args: [Wrapper<CoroutineClosure(DefId(0:23 ~ topic_read_in_transaction_example[dee8]::main::{closure#0}), [i16, Binder { value: extern "RustCall" fn(std::future::ResumeTy, (&'^0 (),)) -> ((), ()), bound_vars: [Region(BrAnon)] }, (), Binder { value: fn(), bound_vars: [Region(BrEnv)] }])>], .. })): NoSolution
  --> ydb/examples/topic-read-in-transaction-example.rs:29:24
   |
29 |     wrap(async |_| {}).method();
   |                        ^^^^^^
   |
note: delayed at /rustc-dev/3659db0d3e2cd634c766fcda79ed118eca31a9fd/compiler/rustc_borrowck/src/type_check/mod.rs:1989:17 - disabled backtrace
  --> ydb/examples/topic-read-in-transaction-example.rs:29:24
   |
29 |     wrap(async |_| {}).method();
   |                        ^^^^^^

Originally found by @liferooter, reduced by me.

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 compiling the reduced Rust example from the issue and confirm both the delayed fully_perform ICE and broken MIR error. Read compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs and compiler/rustc_borrowck/src/type_check/mod.rs around the reported locations, then trace the associated-type projection and async FnMut cast. Done means the example no longer produces an internal compiler error or broken MIR.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.