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

Add support for attribute on struct literal field #1462

Closed
joshlf opened this issue Apr 19, 2017 · 1 comment · Fixed by #1634
Closed

Add support for attribute on struct literal field #1462

joshlf opened this issue Apr 19, 2017 · 1 comment · Fixed by #1634

Comments

@joshlf
Copy link

joshlf commented Apr 19, 2017

rustfmt is currently unable to format code which uses the new (and unstable) attributes on struct fields feature. Demonstration:

$ echo '
> struct Foo {
>     foo: usize,
>     #[cfg(feature = "include-bar")]
>     bar: usize,
> }
> 
> fn new_foo() -> Foo {
>     Foo { 
>         foo: 0,
>         #[cfg(feature = "include-bar")]
>         bar: 0,
>     }
> }
> ' | rustfmt
error: expected identifier, found `#`
  --> stdin:14:9
   |
14 |         #[cfg(feature = "include-bar")]
   |         ^

Interestingly, the same code on the Rust playground is simply formatted to remove the #[cfg(feature = "include-bar")] annotation, producing:

struct Foo {
    foo: usize,
    #[cfg(feature = "include-bar")]
    bar: usize,
}

fn new_foo() -> Foo {
    Foo { foo: 0, bar: 0 }
}
@nrc
Copy link
Member

nrc commented May 1, 2017

I think this just needs us to update the parser (Syntex)

topecongiro added a commit to topecongiro/rustfmt that referenced this issue Jun 5, 2017
@nrc nrc closed this as completed in #1634 Jun 6, 2017
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

Successfully merging a pull request may close this issue.

2 participants