Rustfmt: Implement field_init_shorthand feature

Created on 10 Nov 2016  路  5Comments  路  Source: rust-lang/rustfmt

#![feature(field_init_shorthand)]

struct AA{}
struct BB{}

struct CC {
    a: AA,
    b: BB
}

impl CC {
    fn new(a: AA, b: BB) -> Self {
        Self { a, b }
    }
}

cargo fmt error:

error: expected `:`, found `,`
  --> /tmp/foo/src/lib.rs:13:17
   |
13 |         Self { a, b }
   |                 ^

good first issue p-high

Most helpful comment

It appears that this works in the latest rustfmt, but it defaults to expanding out the shorthand. I think that the default should be to always use the shorthand when possible.

All 5 comments

Weird. Looks like it doesn't error anymore on master. This works. Instead it just inserts the field names. I don't see the commit changing it though.

Is there any progress on this?

It appears that this works in the latest rustfmt, but it defaults to expanding out the shorthand. I think that the default should be to always use the shorthand when possible.

Was this page helpful?
0 / 5 - 0 ratings