Keep brace on same line as `match` when using `ClosingNextLine`.
);
opts.optflag("", "all", "format all packages (only usable in workspaces)");
+ // If there is any invalid argument passed to `cargo fmt`, return without formatting.
+ if let Some(arg) = env::args()
+ .skip(2)
+ .take_while(|a| a != "--")
+ .find(|a| !a.starts_with('-'))
+ {
+ print_usage(&opts, &format!("Invalid argument: `{}`.", arg));
+ return failure;
+ }
+
let matches = match opts.parse(env::args().skip(1).take_while(|a| a != "--")) {
Ok(m) => m,
Err(e) => {
.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 {
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.
}
impl Range {
- fn new(lo: usize, hi: usize) -> Range {
+ pub fn new(lo: usize, hi: usize) -> Range {
Range { lo: lo, hi: hi }
}
FileLines(None)
}
- fn from_ranges(mut ranges: HashMap<String, Vec<Range>>) -> FileLines {
+ pub fn from_ranges(mut ranges: HashMap<String, Vec<Range>>) -> FileLines {
normalize_ranges(&mut ranges);
FileLines(Some(ranges))
}
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),
};
let comma_tactic = if suppress_comma {
SeparatorTactic::Never
} else {
- SeparatorTactic::Always
+ context.config.trailing_comma()
};
let fmt = ListFormatting {
#[inline]
pub fn last_line_extendable(s: &str) -> bool {
s.lines().last().map_or(false, |s| {
- s.trim()
- .chars()
- .all(|c| c == ')' || c == ']' || c == '}' || c == '?')
+ s.ends_with("\"#") ||
+ s.trim()
+ .chars()
+ .all(|c| c == ')' || c == ']' || c == '}' || c == '?')
})
}
})
?;
}
+
+fn issue1392() {
+ test_method(r#"
+ if foo {
+ a();
+ }
+ else {
+ b();
+ }
+ "#.trim());
+}
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),
+ }
}
in_binder(f, tcx, &ty::Binder(""), Some(tap))
})?;
}
+
+fn issue1392() {
+ test_method(
+ r#"
+ if foo {
+ a();
+ }
+ else {
+ b();
+ }
+ "#.trim(),
+ );
+}
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)
+ }
}