-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed as not planned
Labels
breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Description
Zig currently uses _
in five places:
- marking a parameter as unused (
fn foo(_: u32) void
) - marking an expression value as unused (
_ = func();
) - marking a named variable as unused (
_ = variable;
) - marking an enum as extensible (
enum (u8) { _ }
) - declaring a padding field (
_: u6,
)
This proposal is to replace the first three uses with a new keyword, unused
. It behaves as follows:
- On parameters,
fn foo(unused index: u32) void
Allowing a name here can improve documentation, and make it easier to notice if the parameter is actually needed. However, sometimes names are not needed, so we could also allow the syntax fn foo(unused: u32) void
. Since unused
is a keyword, this is not shadowing and can be properly identified by the parser.
- On locals,
unused
can be used in the place ofconst
orvar
. As in,
unused result = func(); // result can be named for better documentation
unused = func(); // name is optional
unused result: u32 = func(); // type annotations are also allowed
unused: u32 = func(); // even without a name
unused = variable; // this could be a compile error if `variable` is a local or parameter, unused should instead be placed on the declaration of variable.
As you might expect, attempting to use a variable declared as unused
is a compile error.
This change is breaking, but zig fmt
would be able to perform most of the update correctly.
After this change, _
would be used exclusively for extensible enums and padding fields.
ikskuh, Luukdegram, scheibo, spenczar, natecraddock and 15 moremwaitzman, czrptr, nektro, tauoverpi, luehmann and 47 morearetrace, voltflake, 90-008 and likerncryptocode, ikskuh, natecraddock and naeukomuw, marler8997, matu3ba and deflock
Metadata
Metadata
Assignees
Labels
breakingImplementing this issue could cause existing code to no longer compile or have different behavior.Implementing this issue could cause existing code to no longer compile or have different behavior.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.