## [Unreleased]
+### Added
+
+- Add `use_field_init_shorthand` config option.
+
## [0.3.6] 2018-01-18
### Fixed
}
```
+## `use_field_init_shorthand`
+
+Use field initialize shorthand if possible.
+
+- **Default value**: `false`
+- **Possible values**: `true`, `false`
+- **Stable**: No
+
+#### `false` (default):
+
+```rust
+struct Foo {
+ x: u32,
+ y: u32,
+ z: u32,
+}
+
+fn main() {
+ let x = 1;
+ let y = 2;
+ let z = 3;
+ let a = Foo { x: x, y: y, z: z };
+}
+```
+
+#### `true`:
+
+```rust
+struct Foo {
+ x: u32,
+ y: u32,
+ z: u32,
+}
+
+fn main() {
+ let x = 1;
+ let y = 2;
+ let z = 3;
+ let a = Foo { x, y, z };
+}
+```
+
## `use_try_shorthand`
Replace uses of the try! macro by the ? shorthand
condense_wildcard_suffixes: bool, false, false, "Replace strings of _ wildcards by a single .. \
in tuple patterns";
force_explicit_abi: bool, true, true, "Always print the abi for extern items";
+ use_field_init_shorthand: bool, false, false, "Use field initialization shorthand if possible";
// Control options (changes the operation of rustfmt, rather than the formatting)
write_mode: WriteMode, WriteMode::Overwrite, false,
let expr = field.expr.rewrite(context, expr_shape);
match expr {
- Some(ref e) if e.as_str() == name => Some(attrs_str + &name),
+ Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => {
+ Some(attrs_str + &name)
+ }
Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)),
None => {
let expr_offset = shape.indent.block_indent(context.config);
--- /dev/null
+// rustfmt-use_field_init_shorthand: false
+// Use field initialization shorthand if possible.
+
+fn main() {
+ let a = Foo {
+ x: x,
+ y: y,
+ z: z,
+ };
+
+ let b = Bar {
+ x: x,
+ y: y,
+ #[attr]
+ z: z,
+ #[rustfmt_skip]
+ skipped: skipped,
+ };
+}
--- /dev/null
+// rustfmt-use_field_init_shorthand: true
+// Use field initialization shorthand if possible.
+
+fn main() {
+ let a = Foo {
+ x: x,
+ y: y,
+ z: z,
+ };
+
+ let b = Bar {
+ x: x,
+ y: y,
+ #[attr]
+ z: z,
+ #[rustfmt_skip]
+ skipped: skipped,
+ };
+}
+++ /dev/null
-// Use field initialization shorthand if possible.
-
-fn main() {
- let a = Foo {
- x: x,
- y: y,
- z: z,
- };
-
- let b = Bar {
- x: x,
- y: y,
- #[attr]
- z: z,
- #[rustfmt_skip]
- skipped: skipped,
- };
-}
hair::PatternRef::Hair(pattern),
&lvalue,
);
- ArgDecl { ty }
+ ArgDecl { ty: ty }
},
);
}
--- /dev/null
+// rustfmt-use_field_init_shorthand: false
+// Use field initialization shorthand if possible.
+
+fn main() {
+ let a = Foo { x: x, y: y, z: z };
+
+ let b = Bar {
+ x: x,
+ y: y,
+ #[attr]
+ z: z,
+ #[rustfmt_skip]
+ skipped: skipped,
+ };
+}
--- /dev/null
+// rustfmt-use_field_init_shorthand: true
+// Use field initialization shorthand if possible.
+
+fn main() {
+ let a = Foo { x, y, z };
+
+ let b = Bar {
+ x,
+ y,
+ #[attr]
+ z,
+ #[rustfmt_skip]
+ skipped: skipped,
+ };
+}
+++ /dev/null
-// Use field initialization shorthand if possible.
-
-fn main() {
- let a = Foo { x, y, z };
-
- let b = Bar {
- x,
- y,
- #[attr]
- z,
- #[rustfmt_skip]
- skipped: skipped,
- };
-}