Skip to content

borrowck: mutability and use-while-moved diagnostics miss ty::CoroutineClosure #605

Description

@SebTardif

Summary

Several borrowck diagnostic paths only pattern-match ty::Closure, so async/coroutine closures (ty::CoroutineClosure) get weaker or missing help:

  1. mutability_errors.rs – mutating an upvar only calls show_mutating_upvar when the place type is ty::Closure (two sites: direct local and via ty::Ref(_, ty, Mut)).
  2. conflict_errors.rsneeds_note suppresses the generic move note only for ty::Closure with a closure_kind_origin; coroutine closures always get the extra note even when a better origin note applies.

Related paths were already fixed in describe_field / moved-or-invoked notes (issue/PR cluster around #576 / #569).

Origin

Audit of incomplete CoroutineClosure match arms in borrowck 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/mutability_errors.rs#L468-L470

https://github.com/rust-lang/rust/blob/f28ac764c36/compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs#L521-L525

https://github.com/rust-lang/rust/blob/f28ac764c36/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs#L276-L281

Suggested fix

Use ty::Closure(id, _) | ty::CoroutineClosure(id, _) in all three sites (same pattern as PR #576 on diagnostics/mod.rs).

Impact

Low. Wrong/missing suggestions and notes for async-closure borrow errors, not incorrect accept/reject of programs.

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