Skip to content

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

Closed
@SimonSapin

Description

@SimonSapin
Contributor

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

Activity

rapha

rapha commented on Feb 4, 2014

@rapha
Contributor

OCaml has this. It's nice. I'd support it.

alexcrichton

alexcrichton commented on Feb 11, 2014

@alexcrichton
Member

Closed with [my comment] on #11994.

alexcrichton

alexcrichton commented on Feb 11, 2014

@alexcrichton
Member
nham

nham commented on Aug 18, 2014

@nham
Contributor

Triage bump.

eddyb

eddyb commented on Aug 18, 2014

@eddyb
Member

Shouldn't this have to go through the RFC process now?

rust-highfive

rust-highfive commented on Sep 24, 2014

@rust-highfive
Contributor

This issue has been moved to the RFCs repo: rust-lang/rfcs#306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @rapha@alexcrichton@eddyb@SimonSapin@nham

        Issue actions

          RFC: Add syntaxic sugar for struct expressions fields from variables of the same name · Issue #11990 · rust-lang/rust