Apply config.trailing_comma wherever possible
This commit is contained in:
parent
f2fd4fbf2c
commit
512c8c1edf
14
src/expr.rs
14
src/expr.rs
@ -1478,6 +1478,7 @@ fn rewrite_match(
|
||||
.codemap
|
||||
.span_after(mk_sp(cond.span.hi, arm_start_pos(&arms[0])), "{");
|
||||
|
||||
let arm_num = arms.len();
|
||||
for (i, arm) in arms.iter().enumerate() {
|
||||
// Make sure we get the stuff between arms.
|
||||
let missed_str = if i == 0 {
|
||||
@ -1497,12 +1498,21 @@ fn rewrite_match(
|
||||
|
||||
let arm_str = arm.rewrite(&context, arm_shape.with_max_width(context.config));
|
||||
if let Some(ref arm_str) = arm_str {
|
||||
result.push_str(arm_str);
|
||||
// Trim the trailing comma if necessary.
|
||||
if i == arm_num - 1 && context.config.trailing_comma() == SeparatorTactic::Never &&
|
||||
arm_str.ends_with(',')
|
||||
{
|
||||
result.push_str(&arm_str[0..arm_str.len() - 1])
|
||||
} else {
|
||||
result.push_str(arm_str)
|
||||
}
|
||||
} else {
|
||||
// We couldn't format the arm, just reproduce the source.
|
||||
let snippet = context.snippet(mk_sp(arm_start_pos(arm), arm_end_pos(arm)));
|
||||
result.push_str(&snippet);
|
||||
result.push_str(arm_comma(context.config, &arm.body));
|
||||
if context.config.trailing_comma() != SeparatorTactic::Never {
|
||||
result.push_str(arm_comma(context.config, &arm.body))
|
||||
}
|
||||
}
|
||||
}
|
||||
// BytePos(1) = closing match brace.
|
||||
|
@ -2267,12 +2267,12 @@ fn rewrite_args(
|
||||
IndentStyle::Block => {
|
||||
(
|
||||
indent.block_indent(context.config),
|
||||
SeparatorTactic::Vertical,
|
||||
context.config.trailing_comma(),
|
||||
true,
|
||||
)
|
||||
}
|
||||
IndentStyle::Visual if last_line_ends_with_comment => {
|
||||
(arg_indent, SeparatorTactic::Vertical, true)
|
||||
(arg_indent, context.config.trailing_comma(), true)
|
||||
}
|
||||
IndentStyle::Visual => (arg_indent, SeparatorTactic::Never, false),
|
||||
};
|
||||
@ -2564,7 +2564,7 @@ fn rewrite_where_clause_rfc_style(
|
||||
let comma_tactic = if suppress_comma {
|
||||
SeparatorTactic::Never
|
||||
} else {
|
||||
SeparatorTactic::Always
|
||||
context.config.trailing_comma()
|
||||
};
|
||||
|
||||
let fmt = ListFormatting {
|
||||
|
@ -10,4 +10,14 @@ fn main() {
|
||||
let _ = safe_assert_eq!(reply_req_num, request_num, op);
|
||||
return Ok((request_num, op, value));
|
||||
}
|
||||
|
||||
// #1710
|
||||
pub struct FileInput {
|
||||
input: StringInput,
|
||||
file_name: OsString,
|
||||
}
|
||||
match len {
|
||||
Some(len) => Ok(new(self.input, self.pos + len)),
|
||||
None => Err(self),
|
||||
}
|
||||
}
|
||||
|
@ -22,4 +22,14 @@ fn main() {
|
||||
let _ = safe_assert_eq!(reply_req_num, request_num, op);
|
||||
return Ok((request_num, op, value));
|
||||
}
|
||||
|
||||
// #1710
|
||||
pub struct FileInput {
|
||||
input: StringInput,
|
||||
file_name: OsString
|
||||
}
|
||||
match len {
|
||||
Some(len) => Ok(new(self.input, self.pos + len)),
|
||||
None => Err(self)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user