Skip to content

There should be a shorthand for foo: ref foo in struct field patterns. #6137

Closed
@jld

Description

@jld

In a pattern matching a struct (or struct-like enum variant), a field can be bound to a variable of the same name by using Thing { foo, ... } as a shorthand for Thing { foo: foo, ... }. It would be nice if there were a similar shorthand for Thing { foo: ref foo, ... }, when the field can't or shouldn't be copied; possibly Thing { ref foo, ... }, unless that's ambiguous.

Not a big issue, but it would help lower the activation energy for using struct-like variants instead staying with tuple-like variants after the point where they need comments in the definition to keep track of which bool/int/whatever means what (comments which are, of course, not available to the type checker).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions