Skip to content

ConstCx::fn_sig ICE on CoroutineClosure/Coroutine (latent, uncalled) #489

@SebTardif

Description

@SebTardif

Bug

ConstCx::fn_sig() in compiler/rustc_const_eval/src/check_consts/mod.rs:66-75 uses is_closure_like() to check if a def_id is a closure, then destructures with let ty::Closure(_, args) = ty.kind(). The is_closure_like() function returns true for all DefKind::Closure, including ty::Coroutine and ty::CoroutineClosure. When one of these types enters the path, the let-else destructure fails and hits bug!("type_of closure not ty::Closure").

Code at fault

// mod.rs:66-75
pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
    let did = self.def_id().to_def_id();
    if self.tcx.is_closure_like(did) {
        let ty = self.tcx.type_of(did).instantiate_identity().skip_norm_wip();
        let ty::Closure(_, args) = ty.kind() else { bug!("type_of closure not ty::Closure") };
        args.as_closure().sig()
    } else {
        self.tcx.fn_sig(did).instantiate_identity().skip_norm_wip()
    }
}

Status

This method currently has no callers in the compiler (confirmed by grep). The bug is latent: it will ICE when anyone adds a call to ConstCx::fn_sig() for a CoroutineClosure or Coroutine body.

Fix

Add match arms for ty::CoroutineClosure and ty::Coroutine, or narrow the is_closure_like() guard.

Impact

P-high severity (latent ICE) but zero current impact because the method is uncalled. Filing to prevent a future regression when someone adds a caller.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-const-evalConst evaluationI-crashUnexpected panic or crashP-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