forked from rust-lang/rustfmt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix rust-lang#5488 - prevent shorthand init for tuple struct
Closes rust-lang#5488 Fix for rust-lang#5488. Before applying shorthand initialization for structs, check if identifier is a literal (e.g. tuple struct). If yes, then do not apply short hand initialization. Added test case to validate the changes for the fix.
- Loading branch information
Showing
3 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// rustfmt-use_field_init_shorthand: true | ||
fn main() { | ||
// Since MyStruct is a tuple struct, it should not be shorthanded to | ||
// MyStruct { 0 } even if use_field_init_shorthand is enabled. | ||
let instance = MyStruct { 0: 0 }; | ||
|
||
// Since AnotherStruct is not a tuple struct, the shorthand should | ||
// apply. | ||
let a = 10; | ||
let instance = AnotherStruct { a: a }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// rustfmt-use_field_init_shorthand: true | ||
fn main() { | ||
// Since MyStruct is a tuple struct, it should not be shorthanded to | ||
// MyStruct { 0 } even if use_field_init_shorthand is enabled. | ||
let instance = MyStruct { 0: 0 }; | ||
|
||
// Since AnotherStruct is not a tuple struct, the shorthand should | ||
// apply. | ||
let a = 10; | ||
let instance = AnotherStruct { a }; | ||
} |