mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-11 19:46:49 +00:00
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.
This commit is contained in:
parent
6be61bcdd6
commit
f96e56c3a0
@ -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("..");
|
||||
}
|
||||
|
23
tests/target/issue-1397.rs
Normal file
23
tests/target/issue-1397.rs
Normal file
@ -0,0 +1,23 @@
|
||||
pub enum TransactionState {
|
||||
Committed(i64),
|
||||
}
|
||||
|
||||
pub enum Packet {
|
||||
Transaction { state: TransactionState },
|
||||
}
|
||||
|
||||
fn baz(p: Packet) {
|
||||
loop {
|
||||
loop {
|
||||
loop {
|
||||
loop {
|
||||
if let Packet::Transaction {
|
||||
state: TransactionState::Committed(ts, ..), ..
|
||||
} = p {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user