rust/tests/target/issue-5488.rs
Rajiv Sharma 5391847ea5 Fix #5488 - prevent shorthand init for tuple struct
Closes #5488

Fix for #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.
2023-02-01 21:33:19 -06:00

18 lines
437 B
Rust

// rustfmt-use_field_init_shorthand: true
struct MyStruct(u32);
struct AnotherStruct {
a: u32,
}
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 };
}