Skip to content

Commit 1f738ea

Browse files
committed
Cargo fmt
1 parent f8439ce commit 1f738ea

File tree

14 files changed

+96
-43
lines changed

14 files changed

+96
-43
lines changed

src/bin/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fn main() {
3636

3737
let exit_code = match execute(&opts) {
3838
Ok((write_mode, summary)) => {
39-
if summary.has_operational_errors() || summary.has_parsing_errors()
39+
if summary.has_operational_errors()
40+
|| summary.has_parsing_errors()
4041
|| (summary.has_diff && write_mode == WriteMode::Check)
4142
{
4243
1

src/chains.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
265265
nested_shape.indent.to_string_with_newline(context.config)
266266
};
267267

268-
let first_connector = if is_small_parent || fits_single_line
268+
let first_connector = if is_small_parent
269+
|| fits_single_line
269270
|| last_line_extendable(&parent_rewrite)
270271
|| context.config.indent_style() == IndentStyle::Visual
271272
{
@@ -275,7 +276,8 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
275276
};
276277

277278
let result = if is_small_parent && rewrites.len() > 1 {
278-
let second_connector = if fits_single_line || rewrites[1] == "?"
279+
let second_connector = if fits_single_line
280+
|| rewrites[1] == "?"
279281
|| last_line_extendable(&rewrites[0])
280282
|| context.config.indent_style() == IndentStyle::Visual
281283
{

src/closures.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,10 @@ fn get_inner_expr<'a>(
109109

110110
// Figure out if a block is necessary.
111111
fn needs_block(block: &ast::Block, prefix: &str, context: &RewriteContext) -> bool {
112-
is_unsafe_block(block) || block.stmts.len() > 1
113-
|| block_contains_comment(block, context.codemap) || prefix.contains('\n')
112+
is_unsafe_block(block)
113+
|| block.stmts.len() > 1
114+
|| block_contains_comment(block, context.codemap)
115+
|| prefix.contains('\n')
114116
}
115117

116118
// Rewrite closure with a single expression wrapping its body with block.

src/comment.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,9 @@ fn light_rewrite_comment(
579579
/// Does not trim all whitespace. If a single space is trimmed from the left of the string,
580580
/// this function returns true.
581581
fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> (&'a str, bool) {
582-
if line.starts_with("//! ") || line.starts_with("/// ") || line.starts_with("/*! ")
582+
if line.starts_with("//! ")
583+
|| line.starts_with("/// ")
584+
|| line.starts_with("/*! ")
583585
|| line.starts_with("/** ")
584586
{
585587
(&line[4..], true)
@@ -589,13 +591,18 @@ fn left_trim_comment_line<'a>(line: &'a str, style: &CommentStyle) -> (&'a str,
589591
} else {
590592
(&line[opener.trim_right().len()..], false)
591593
}
592-
} else if line.starts_with("/* ") || line.starts_with("// ") || line.starts_with("//!")
593-
|| line.starts_with("///") || line.starts_with("** ")
594+
} else if line.starts_with("/* ")
595+
|| line.starts_with("// ")
596+
|| line.starts_with("//!")
597+
|| line.starts_with("///")
598+
|| line.starts_with("** ")
594599
|| line.starts_with("/*!")
595600
|| (line.starts_with("/**") && !line.starts_with("/**/"))
596601
{
597602
(&line[3..], line.chars().nth(2).unwrap() == ' ')
598-
} else if line.starts_with("/*") || line.starts_with("* ") || line.starts_with("//")
603+
} else if line.starts_with("/*")
604+
|| line.starts_with("* ")
605+
|| line.starts_with("//")
599606
|| line.starts_with("**")
600607
{
601608
(&line[2..], line.chars().nth(1).unwrap() == ' ')

src/config/summary.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ impl Summary {
9090
}
9191

9292
pub fn has_no_errors(&self) -> bool {
93-
!(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors
93+
!(self.has_operational_errors
94+
|| self.has_parsing_errors
95+
|| self.has_formatting_errors
9496
|| self.has_diff)
9597
}
9698

src/expr.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,10 @@ where
474474
.map(|first_line| first_line.ends_with('{'))
475475
.unwrap_or(false);
476476
if !rhs_result.contains('\n') || allow_same_line {
477-
let one_line_width = last_line_width(&lhs_result) + pp.infix.len()
478-
+ first_line_width(rhs_result) + pp.suffix.len();
477+
let one_line_width = last_line_width(&lhs_result)
478+
+ pp.infix.len()
479+
+ first_line_width(rhs_result)
480+
+ pp.suffix.len();
479481
if one_line_width <= shape.width {
480482
return Some(format!(
481483
"{}{}{}{}",
@@ -558,7 +560,9 @@ fn rewrite_empty_block(
558560
let user_str = user_str.trim();
559561
if user_str.starts_with('{') && user_str.ends_with('}') {
560562
let comment_str = user_str[1..user_str.len() - 1].trim();
561-
if block.stmts.is_empty() && !comment_str.contains('\n') && !comment_str.starts_with("//")
563+
if block.stmts.is_empty()
564+
&& !comment_str.contains('\n')
565+
&& !comment_str.starts_with("//")
562566
&& comment_str.len() + 4 <= shape.width
563567
{
564568
return Some(format!("{}{{ {} }}", prefix, comment_str));
@@ -1241,8 +1245,10 @@ pub fn is_simple_block(
12411245
attrs: Option<&[ast::Attribute]>,
12421246
codemap: &CodeMap,
12431247
) -> bool {
1244-
(block.stmts.len() == 1 && stmt_is_expr(&block.stmts[0])
1245-
&& !block_contains_comment(block, codemap) && attrs.map_or(true, |a| a.is_empty()))
1248+
(block.stmts.len() == 1
1249+
&& stmt_is_expr(&block.stmts[0])
1250+
&& !block_contains_comment(block, codemap)
1251+
&& attrs.map_or(true, |a| a.is_empty()))
12461252
}
12471253

12481254
/// Checks whether a block contains at most one statement or expression, and no
@@ -1252,7 +1258,8 @@ pub fn is_simple_block_stmt(
12521258
attrs: Option<&[ast::Attribute]>,
12531259
codemap: &CodeMap,
12541260
) -> bool {
1255-
block.stmts.len() <= 1 && !block_contains_comment(block, codemap)
1261+
block.stmts.len() <= 1
1262+
&& !block_contains_comment(block, codemap)
12561263
&& attrs.map_or(true, |a| a.is_empty())
12571264
}
12581265

@@ -1263,7 +1270,8 @@ pub fn is_empty_block(
12631270
attrs: Option<&[ast::Attribute]>,
12641271
codemap: &CodeMap,
12651272
) -> bool {
1266-
block.stmts.is_empty() && !block_contains_comment(block, codemap)
1273+
block.stmts.is_empty()
1274+
&& !block_contains_comment(block, codemap)
12671275
&& attrs.map_or(true, |a| inner_attributes(a).is_empty())
12681276
}
12691277

@@ -1778,7 +1786,8 @@ pub fn wrap_struct_field(
17781786
one_line_width: usize,
17791787
) -> String {
17801788
if context.config.indent_style() == IndentStyle::Block
1781-
&& (fields_str.contains('\n') || !context.config.struct_lit_single_line()
1789+
&& (fields_str.contains('\n')
1790+
|| !context.config.struct_lit_single_line()
17821791
|| fields_str.len() > one_line_width)
17831792
{
17841793
format!(
@@ -2104,7 +2113,8 @@ fn choose_rhs<R: Rewrite>(
21042113
}
21052114

21062115
pub fn prefer_next_line(orig_rhs: &str, next_line_rhs: &str, rhs_tactics: RhsTactics) -> bool {
2107-
rhs_tactics == RhsTactics::ForceNextLine || !next_line_rhs.contains('\n')
2116+
rhs_tactics == RhsTactics::ForceNextLine
2117+
|| !next_line_rhs.contains('\n')
21082118
|| count_newlines(orig_rhs) > count_newlines(next_line_rhs) + 1
21092119
}
21102120

src/imports.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ impl UseTree {
489489
}
490490

491491
fn share_prefix(&self, other: &UseTree) -> bool {
492-
if self.path.is_empty() || other.path.is_empty() || self.attrs.is_some()
492+
if self.path.is_empty()
493+
|| other.path.is_empty()
494+
|| self.attrs.is_some()
493495
|| !self.same_visibility(other)
494496
{
495497
false

src/items.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ impl<'a> FmtVisitor<'a> {
313313
rewrite_fn_base(&context, indent, ident, fn_sig, span, newline_brace, true)?;
314314

315315
// 2 = ` {`
316-
if self.config.brace_style() == BraceStyle::AlwaysNextLine || force_newline_brace
316+
if self.config.brace_style() == BraceStyle::AlwaysNextLine
317+
|| force_newline_brace
317318
|| last_line_width(&result) + 2 > self.shape().width
318319
{
319320
newline_brace = true;
@@ -376,7 +377,8 @@ impl<'a> FmtVisitor<'a> {
376377

377378
let codemap = self.get_context().codemap;
378379

379-
if self.config.empty_item_single_line() && is_empty_block(block, None, codemap)
380+
if self.config.empty_item_single_line()
381+
&& is_empty_block(block, None, codemap)
380382
&& self.block_indent.width() + fn_str.len() + 2 <= self.config.max_width()
381383
{
382384
return Some(format!("{}{{}}", fn_str));
@@ -755,7 +757,9 @@ fn is_impl_single_line(
755757
let open_pos = snippet.find_uncommented("{")? + 1;
756758

757759
Some(
758-
context.config.empty_item_single_line() && items.is_empty() && !result.contains('\n')
760+
context.config.empty_item_single_line()
761+
&& items.is_empty()
762+
&& !result.contains('\n')
759763
&& result.len() + where_clause_str.len() <= context.config.max_width()
760764
&& !contains_comment(&snippet[open_pos..]),
761765
)
@@ -1194,7 +1198,8 @@ pub fn format_struct_struct(
11941198
// 1 = `}`
11951199
let overhead = if fields.is_empty() { 1 } else { 0 };
11961200
let total_width = result.len() + generics_str.len() + overhead;
1197-
if !generics_str.is_empty() && !generics_str.contains('\n')
1201+
if !generics_str.is_empty()
1202+
&& !generics_str.contains('\n')
11981203
&& total_width > context.config.max_width()
11991204
{
12001205
result.push('\n');
@@ -1223,7 +1228,9 @@ pub fn format_struct_struct(
12231228
one_line_budget,
12241229
)?;
12251230

1226-
if !items_str.contains('\n') && !result.contains('\n') && items_str.len() <= one_line_budget
1231+
if !items_str.contains('\n')
1232+
&& !result.contains('\n')
1233+
&& items_str.len() <= one_line_budget
12271234
&& !last_line_contains_single_line_comment(&items_str)
12281235
{
12291236
Some(format!("{} {} }}", result, items_str))
@@ -1904,7 +1911,8 @@ fn rewrite_fn_base(
19041911
} else {
19051912
result.push('(');
19061913
}
1907-
if context.config.spaces_within_parens_and_brackets() && !fd.inputs.is_empty()
1914+
if context.config.spaces_within_parens_and_brackets()
1915+
&& !fd.inputs.is_empty()
19081916
&& result.ends_with('(')
19091917
{
19101918
result.push(' ')
@@ -2478,8 +2486,10 @@ fn rewrite_where_clause_rfc_style(
24782486
let newline_after_where = comment_separator(&comment_after, clause_shape);
24792487

24802488
// 6 = `where `
2481-
let clause_sep = if where_clause_option.compress_where && comment_before.is_empty()
2482-
&& comment_after.is_empty() && !preds_str.contains('\n')
2489+
let clause_sep = if where_clause_option.compress_where
2490+
&& comment_before.is_empty()
2491+
&& comment_after.is_empty()
2492+
&& !preds_str.contains('\n')
24832493
&& 6 + preds_str.len() <= shape.width || where_single_line
24842494
{
24852495
Cow::from(" ")
@@ -2590,7 +2600,8 @@ fn rewrite_where_clause(
25902600
} else {
25912601
terminator.len()
25922602
};
2593-
if density == Density::Tall || preds_str.contains('\n')
2603+
if density == Density::Tall
2604+
|| preds_str.contains('\n')
25942605
|| shape.indent.width() + " where ".len() + preds_str.len() + end_length > shape.width
25952606
{
25962607
Some(format!(
@@ -2682,7 +2693,8 @@ fn format_generics(
26822693
|| (generics.where_clause.predicates.is_empty()
26832694
&& trimmed_last_line_width(&result) == 1)
26842695
} else {
2685-
brace_pos == BracePos::ForceSameLine || trimmed_last_line_width(&result) == 1
2696+
brace_pos == BracePos::ForceSameLine
2697+
|| trimmed_last_line_width(&result) == 1
26862698
|| brace_style != BraceStyle::AlwaysNextLine
26872699
};
26882700
if brace_pos == BracePos::None {

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ fn format_lines(
490490

491491
// Check for any line width errors we couldn't correct.
492492
let error_kind = ErrorKind::LineOverflow(line_len, config.max_width());
493-
if line_len > config.max_width() && !is_skipped_line(cur_line, skipped_range)
493+
if line_len > config.max_width()
494+
&& !is_skipped_line(cur_line, skipped_range)
494495
&& should_report_error(config, kind, is_string, error_kind)
495496
{
496497
errors.push(FormattingError {
@@ -905,7 +906,8 @@ pub fn format_and_emit_report(input: Input, config: &Config) -> FmtResult<Summar
905906
if report.has_warnings() {
906907
match term::stderr() {
907908
Some(ref t)
908-
if use_colored_tty(config.color()) && t.supports_color()
909+
if use_colored_tty(config.color())
910+
&& t.supports_color()
909911
&& t.supports_attr(term::Attr::Bold) =>
910912
{
911913
match report.print_warnings_fancy(term::stderr().unwrap()) {

src/lists.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ where
192192
let total_sep_len = sep.len() * sep_count.checked_sub(1).unwrap_or(0);
193193
let real_total = total_width + total_sep_len;
194194

195-
if real_total <= limit && !pre_line_comments
195+
if real_total <= limit
196+
&& !pre_line_comments
196197
&& !items.into_iter().any(|item| item.as_ref().is_multiline())
197198
{
198199
DefinitiveListTactic::Horizontal
@@ -404,8 +405,10 @@ where
404405
if !starts_with_newline(comment) {
405406
let mut comment_alignment =
406407
post_comment_alignment(item_max_width, inner_item.len());
407-
if first_line_width(&formatted_comment) + last_line_width(&result)
408-
+ comment_alignment + 1 > formatting.config.max_width()
408+
if first_line_width(&formatted_comment)
409+
+ last_line_width(&result)
410+
+ comment_alignment
411+
+ 1 > formatting.config.max_width()
409412
{
410413
item_max_width = None;
411414
formatted_comment = rewrite_post_comment(&mut item_max_width)?;
@@ -431,7 +434,9 @@ where
431434
item_max_width = None;
432435
}
433436

434-
if formatting.preserve_newline && !last && tactic == DefinitiveListTactic::Vertical
437+
if formatting.preserve_newline
438+
&& !last
439+
&& tactic == DefinitiveListTactic::Vertical
435440
&& item.new_lines
436441
{
437442
item_max_width = None;
@@ -458,7 +463,8 @@ where
458463
let item = item.as_ref();
459464
let inner_item_width = item.inner_as_ref().len();
460465
if !first
461-
&& (item.is_different_group() || item.post_comment.is_none()
466+
&& (item.is_different_group()
467+
|| item.post_comment.is_none()
462468
|| inner_item_width + overhead > max_budget)
463469
{
464470
return max_width;

src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ pub fn rewrite_macro_inner(
269269
let nested_shape = mac_shape.block_indent(context.config.tab_spaces());
270270
let lhs = arg_vec[0].rewrite(context, nested_shape)?;
271271
let rhs = arg_vec[1].rewrite(context, nested_shape)?;
272-
if !lhs.contains('\n') && !rhs.contains('\n')
272+
if !lhs.contains('\n')
273+
&& !rhs.contains('\n')
273274
&& lhs.len() + rhs.len() + total_overhead <= shape.width
274275
{
275276
Some(format!("{}{}{}; {}{}", macro_name, lbr, lhs, rhs, rbr))

src/matches.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ fn rewrite_guard(
498498
fn nop_block_collapse(block_str: Option<String>, budget: usize) -> Option<String> {
499499
debug!("nop_block_collapse {:?} {}", block_str, budget);
500500
block_str.map(|block_str| {
501-
if block_str.starts_with('{') && budget >= 2
501+
if block_str.starts_with('{')
502+
&& budget >= 2
502503
&& (block_str[1..].find(|c: char| !c.is_whitespace()).unwrap() == block_str.len() - 2)
503504
{
504505
"{}".to_owned()

src/overflow.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
235235

236236
fn try_overflow_last_item(&self, list_items: &mut Vec<ListItem>) -> DefinitiveListTactic {
237237
// 1 = "("
238-
let combine_arg_with_callee = self.items.len() == 1 && self.items[0].to_expr().is_some()
238+
let combine_arg_with_callee = self.items.len() == 1
239+
&& self.items[0].to_expr().is_some()
239240
&& self.ident.len() + 1 <= self.context.config.tab_spaces();
240241
let overflow_last = combine_arg_with_callee || can_be_overflowed(self.context, self.items);
241242

@@ -311,7 +312,9 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
311312
// Use horizontal layout for a function with a single argument as long as
312313
// everything fits in a single line.
313314
// `self.one_line_width == 0` means vertical layout is forced.
314-
if self.items.len() == 1 && self.one_line_width != 0 && !list_items[0].has_comment()
315+
if self.items.len() == 1
316+
&& self.one_line_width != 0
317+
&& !list_items[0].has_comment()
315318
&& !list_items[0].inner_as_ref().contains('\n')
316319
&& ::lists::total_item_width(&list_items[0]) <= self.one_line_width
317320
{
@@ -462,7 +465,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
462465
let (extendable, items_str) = self.rewrite_items()?;
463466

464467
// If we are using visual indent style and failed to format, retry with block indent.
465-
if !self.context.use_block_indent() && need_block_indent(&items_str, self.nested_shape)
468+
if !self.context.use_block_indent()
469+
&& need_block_indent(&items_str, self.nested_shape)
466470
&& !extendable
467471
{
468472
self.context.use_block.replace(true);

src/types.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ fn rewrite_segment(
230230
if let Some(ref params) = segment.parameters {
231231
match **params {
232232
ast::PathParameters::AngleBracketed(ref data)
233-
if !data.lifetimes.is_empty() || !data.types.is_empty()
233+
if !data.lifetimes.is_empty()
234+
|| !data.types.is_empty()
234235
|| !data.bindings.is_empty() =>
235236
{
236237
let param_list = data.lifetimes

0 commit comments

Comments
 (0)