Skip to content

Implement syntax for anonymous unboxed closures #14449

Closed
@pcwalton

Description

@pcwalton

This is part of unboxed closures. cc @nikomatsakis

I suggest that we adopt the following syntax for now. We can change it and bikeshed it later.

|&: x, y| x + y // Fn
|&mut: x, y| x + y // FnMut (the commonest, eventually the default)
|: x, y| x + y // FnOnce

These create anonymous struct types that move their upvars (cf. #12831) and implement the Fn/FnMut/FnOnce traits.

Per discussion last week I believe that this is necessary for 1.0. Nominating for backcompat-lang because we will remove the old closures after this is done.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-type-systemArea: Type systemB-RFC-approvedBlocker: Approved by a merged RFC but not yet implemented.C-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions