Skip to content

borrowck: is_closure_fn_mut ignores DefiningTy::CoroutineClosure #606

Description

@SebTardif

Summary

compiler/rustc_borrowck/src/diagnostics/region_errors.rs is_closure_fn_mut only inspects DefiningTy::Closure when the error region is a ClosureEnv late-param region. For async/coroutine-closure MIR (DefiningTy::CoroutineClosure), it always returns false even when args.as_coroutine_closure().kind() == FnMut.

That can change region-error wording/suggestions that branch on is_closure_fn_mut for coroutine closures.

Origin

Audit of incomplete CoroutineClosure handling in borrowck region diagnostics, SebTardif/rust fork of rust-lang/rust.

Affected code (upstream tip at audit time)

https://github.com/rust-lang/rust/blob/f28ac764c36/compiler/rustc_borrowck/src/diagnostics/region_errors.rs#L177-L188

&& let DefiningTy::Closure(_, args) = self.regioncx.universal_regions().defining_ty
{
    return args.as_closure().kind() == ty::ClosureKind::FnMut;
}

Suggested fix

Match DefiningTy::CoroutineClosure(_, args) and compare args.as_coroutine_closure().kind() to FnMut (same ClosureEnv late-param region shape as normal closures).

Impact

Low. Diagnostic quality for async/coroutine-closure region errors only.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions