diff options
| author | Jon Gjengset <jon@thesquareplanet.com> | 2017-03-26 01:16:45 -0400 |
|---|---|---|
| committer | Nick Cameron <nrc@ncameron.org> | 2017-03-26 18:16:45 +1300 |
| commit | f96e56c3a024fd6b8e5545e21299cdefe17c5965 (patch) | |
| tree | db502dac6b405a58d1297bb97c22b94ada593782 /src/patterns.rs | |
| parent | 6be61bcdd6252b529f5a14765fb7cb01be943f66 (diff) | |
Avoid extra comma in vertical single-field struct patterns (#1403)
* Add (failing) test for #1397 * Fix for #1397 Specifically, we end up double-adding a trailing comma for single-member struct patterns that are arranged vertically. One is added by write_list (since such structs return true for needs_trailing_separator), and another is added by the if in the old code.
Diffstat (limited to 'src/patterns.rs')
| -rw-r--r-- | src/patterns.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/patterns.rs b/src/patterns.rs index 18def6bfb64..8c81a5ef990 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -13,8 +13,8 @@ use codemap::SpanUtils; use config::{IndentStyle, MultilineStyle}; use rewrite::{Rewrite, RewriteContext}; use utils::{wrap_str, format_mutability}; -use lists::{format_item_list, itemize_list, ListItem, struct_lit_shape, struct_lit_tactic, - shape_for_tactic, struct_lit_formatting, write_list}; +use lists::{DefinitiveListTactic, format_item_list, itemize_list, ListItem, struct_lit_shape, + struct_lit_tactic, shape_for_tactic, struct_lit_formatting, write_list}; use expr::{rewrite_unary_prefix, rewrite_pair}; use types::{rewrite_path, PathContext}; use super::Spanned; @@ -167,7 +167,13 @@ fn rewrite_struct_pat(path: &ast::Path, fields_str.push_str(".."); } else { if !fields_str.is_empty() { - fields_str.push_str(", "); + // there are preceeding struct fields being matched on + if fmt.tactic == DefinitiveListTactic::Vertical { + // if the tactic is Vertical, write_list already added a trailing , + fields_str.push_str(" "); + } else { + fields_str.push_str(", "); + } } fields_str.push_str(".."); } |
