Skip to content

cranelift assert_assignable missing CoroutineClosure, ICE on region mismatch #488

@SebTardif

Description

@SebTardif

Bug

assert_assignable in compiler/rustc_codegen_cranelift/src/value_and_place.rs:935 handles ty::Closure, ty::Coroutine, and ty::CoroutineWitness with component-wise type comparison (iterating over args types), but ty::CoroutineClosure falls through to the _ => arm which does a strict assert_eq!.

When two CoroutineClosure types with the same def_id but different region substitutions are compared (normal during codegen when regions are erased at different stages), the assert_eq! panics because the types are structurally equivalent but not == due to region differences.

Code at fault

// value_and_place.rs:935-983
(&ty::Closure(def_id_a, args_a), &ty::Closure(def_id_b, args_b))
    if def_id_a == def_id_b => { /* component-wise comparison */ }
(&ty::Coroutine(def_id_a, args_a), &ty::Coroutine(def_id_b, args_b))
    if def_id_a == def_id_b => { /* component-wise comparison */ }
(&ty::CoroutineWitness(def_id_a, args_a), &ty::CoroutineWitness(def_id_b, args_b))
    if def_id_a == def_id_b => { /* component-wise comparison */ }
// MISSING: CoroutineClosure
_ => {
    assert_eq!(from_ty, to_ty, "Can't write value with incompatible type...");
}

Fix

Add a (&ty::CoroutineClosure(def_id_a, args_a), &ty::CoroutineClosure(def_id_b, args_b)) arm with the same component-wise comparison logic used by Closure and Coroutine.

Impact

ICE in cranelift debug builds when async closures have differing region substitutions between source and destination types. P-medium because it only affects cranelift backend (not LLVM) and only in debug assertion mode.

Pattern

Same CoroutineClosure-missing-from-match pattern as #477, #478, #479, #483, #484.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-codegenArea: code generationI-crashUnexpected panic or crashP-mediumMedium impact: affects specific usage patternsbugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions