Skip to content

RFC: Add syntaxic sugar for struct expressions fields from variables of the same name #11990

Closed
@SimonSapin

Description

@SimonSapin

The general syntax for a struct pattern is:

StructName { field_name: new_variable_name }

But when the desired variable name is the same as the field name, it does not need to be repeated:

let MyStruct { name } = struct_value;
do_something_with(name);

This proposal is to add similar syntax sugar for struct expressions:

let name = …;
let struct_value = MyStruct { name };

… would be the same as:

let name = …;
let struct_value = MyStruct { name: name };

CC: @eddyb

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