diff options
| author | Rajiv Sharma <rajshar@fb.com> | 2022-08-28 00:36:16 +0100 |
|---|---|---|
| committer | Caleb Cartwright <calebcartwright@users.noreply.github.com> | 2023-02-01 21:33:19 -0600 |
| commit | 5391847ea5a12262704657a0708b1674fb344403 (patch) | |
| tree | f46fbb6540d78ab481a6c5c9270020a6ccb2c4ca /src/expr.rs | |
| parent | e2996a807b411218bb3dca0f2a0e420839cd3875 (diff) | |
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.
Diffstat (limited to 'src/expr.rs')
| -rw-r--r-- | src/expr.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/expr.rs b/src/expr.rs index 0be4c3cf168..91f3cc81bae 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1723,9 +1723,11 @@ pub(crate) fn rewrite_field( let overhead = name.len() + separator.len(); let expr_shape = shape.offset_left(overhead)?; let expr = field.expr.rewrite(context, expr_shape); - + let is_lit = matches!(field.expr.kind, ast::ExprKind::Lit(_)); match expr { - Some(ref e) if e.as_str() == name && context.config.use_field_init_shorthand() => { + Some(ref e) + if !is_lit && e.as_str() == name && context.config.use_field_init_shorthand() => + { Some(attrs_str + name) } Some(e) => Some(format!("{}{}{}{}", attrs_str, name, separator, e)), |
