Skip to content

Add rustfmt support for attribute on struct literal field #41392

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

Closed
joshlf opened this issue Apr 19, 2017 · 2 comments
Closed

Add rustfmt support for attribute on struct literal field #41392

joshlf opened this issue Apr 19, 2017 · 2 comments

Comments

@joshlf
Copy link
Contributor

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 }
}
@sfackler
Copy link
Member

This should probably be filed on https://github.com/rust-lang-nursery/rustfmt.

@steveklabnik
Copy link
Member

yes, please file it over there, thanks!

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

3 participants