Skip to content

OpaqueTypeCollector missing CoroutineClosure, async closure def_ids not collected #483

Description

@SebTardif

Bug

OpaqueTypeCollector in compiler/rustc_hir_analysis/src/check/check.rs:2199 matches ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) but is missing ty::CoroutineClosure(def_id, ..).

When an async closure (stable since Rust 1.85) contains references to opaque types, the CoroutineClosure TyKind variant falls through to the default _ => t.super_visit_with(self) arm instead of being pushed onto self.closures. This means the closure def_id is not collected, potentially causing missed opaque type checks for async closures.

Code at fault

// check.rs:2199
ty::Closure(def_id, ..) | ty::Coroutine(def_id, ..) => {
    self.closures.push(def_id);
    t.super_visit_with(self);
}

Missing: ty::CoroutineClosure(def_id, ..)

Pattern

Same CoroutineClosure-missing-from-match pattern as #477, #478, #479. The CoroutineClosure TyKind variant was added for async closures but many match sites were not updated.

Severity

Diagnostic-only. The closures list is used for opaque type diagnostics, so the impact is limited to potentially missing or incorrect error messages when async closures interact with opaque types.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsCompiler diagnosticsA-type-systemType systemI-wrongWrong result or data corruptionP-lowLow impact: edge case or niche scenariobugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions