Skip to content

syntax: destructuring structs, tuple structs and tuples should be consistent #5830

Closed
@thestinger

Description

@thestinger

These are minor nitpicks, but they might as well be fixed before it's too late.

struct Foo(int, int, int, int);
struct Bar{a: int, b: int, c: int, d: int};

Ignoring all the fields is inconsistent:

let Foo(*) = Foo(5, 5, 5, 5);
let Bar(_) = Bar{a: 5, b: 5, c: 5, d: 5};

It doesn't seem like it's currently possible to ignore all fields of a regular tuple.

I think this would be nicer:

let Foo(*) = Foo(5, 5, 5, 5);
let Bar(*) = Bar{a: 5, b: 5, c: 5, d: 5};
let (*) = (5, 5, 5, 5);

With a struct, you can ignore "the rest", but you can't with a tuple struct or tuple:

let Bar{b: b, _} = Bar{a: 5, b: 5, c: 5, d: 5};

This would be more consistent, and similar to destructuring fixed-size vectors:

let Foo(a, b, *) = Foo(5, 5, 5, 5);
let Foo(*, d) = Foo(5, 5, 5, 5);
let (a, b, *) = (5, 5, 5, 5);
let (*, c, d) = (5, 5, 5, 5);
let Bar{b: b, *} = Bar{a: 5, b: 5, c: 5, d: 5};

An underscore would mean ignoring one field.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustP-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions