Skip to content

RFC: Better/Shorter syntax to declare multiple variables #64602

Closed
@abbychau

Description

@abbychau

When we have multiple variable to be declared, we need to write something like this:

let (mut a, mut b, mut c, mut d) = (false, false, false, false);

There are two obvious factorizations:

The first part is to factorize the mut decorator, so to be let mut (a, b, c, d).
Another part is to spread the value tuple, so to be false.

That

let mut (a,b,c,d) = false;

is short while intuitive.


Last, in the long form

let (mut a, mut b, mut c, mut d) : (bool, bool, bool, bool) = (false, false, false, false);

if the type is required there, then it is able to be shorted to.

let mut (a, b, c, d) : bool = false;

I have thought of making bool and false there a bit more obvious like the JS style spread(not really the spreading meaning here though):
(false..) and (bool..) or using other notations like x!(bool) and [bool], and etc., but I think that keeping the simple form is good enough and because it does not seem to induce much misleadings while reading .

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions