Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: C99-style designated initializers #11936

Closed
edwardw opened this issue Jan 30, 2014 · 4 comments
Closed

RFC: C99-style designated initializers #11936

edwardw opened this issue Jan 30, 2014 · 4 comments

Comments

@edwardw
Copy link
Contributor

edwardw commented Jan 30, 2014

On several occasions I found myself in the need of C99-style designated initializer to initialize a static sparse array, like so:

int a[128] = { [0] = 1, [64] = 2 };

It is just too error-prone, tedious and unsightly to type all remaining zeros. Note C99 designated initializer can also be applied to aggregate types but I doubt it would be as useful in rust.

@lifthrasiir
Copy link
Contributor

What should be its syntax? We already have [expr, expr, expr] and [expr, ..expr] which severely limit remaining choices. For example, [[expr] = expr, <...>] or [expr = expr, <...>] is out, and [[expr]: expr, <...>] or [expr: expr, <...>] is possible but might conflict with #10502.

@kvanbere
Copy link

kvanbere commented Mar 4, 2014

Don't forget unspecified elements need a default fill too in some applications (#12680).

@edwardw
Copy link
Contributor Author

edwardw commented Mar 4, 2014

I was thinking something along the line of macro and / or compile time function evaluation (CTFE) may work but nothing concrete yet.

@thestinger
Copy link
Contributor

This would need to go through the formal RFC process now.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 11, 2024
…l, r=llogiq

Don't emit `struct_field_names` lint if all fields are booleans and don't start with the type's name

Fixes rust-lang#11936.

I only checked that all fields are booleans and not the prefix (nor the suffix) because when I started to list accepted prefixes (like "is", "has", "should", "could", etc), the list was starting to get a bit too long and I thought it was not really worth for such a small change.

r? `@llogiq`

changelog: Don't emit `struct_field_names` lint if all fields are booleans and don't start with the type's name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants