Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e2b9c66

Browse files
committed
Cargo fmt
1 parent d4f7e21 commit e2b9c66

23 files changed

+102
-51
lines changed

src/attr.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,8 @@ impl Rewrite for ast::MetaItem {
229229
None,
230230
&inner_meta_item.ident,
231231
shape,
232-
).map_or(false, |s| s.len() + path.len() + 2 <= shape.width),
232+
)
233+
.map_or(false, |s| s.len() + path.len() + 2 <= shape.width),
233234
_ => false,
234235
}
235236
}

src/bin/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ fn determine_operation(matches: &Matches) -> Result<Operation, ErrorKind> {
421421
// we will do comparison later, so here tries to canonicalize first
422422
// to get the expected behavior.
423423
p.canonicalize().unwrap_or(p)
424-
}).collect();
424+
})
425+
.collect();
425426

426427
Ok(Operation::Format {
427428
files,

src/cargo-fmt/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ fn format_crate(
163163
if verbosity == Verbosity::Verbose {
164164
println!("[{}] {:?}", t.kind, t.path)
165165
}
166-
}).map(|t| t.path)
166+
})
167+
.map(|t| t.path)
167168
.collect();
168169

169170
run_rustfmt(&files, &rustfmt_args, verbosity)

src/chains.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,8 @@ impl<'a> ChainFormatterShared<'a> {
558558
shape.width
559559
} else {
560560
min(shape.width, context.config.width_heuristics().chain_width)
561-
}.saturating_sub(almost_total);
561+
}
562+
.saturating_sub(almost_total);
562563

563564
let all_in_one_line = !self.children.iter().any(ChainItem::is_comment)
564565
&& self.rewrites.iter().all(|s| !s.contains('\n'))
@@ -710,7 +711,8 @@ impl<'a> ChainFormatter for ChainFormatterBlock<'a> {
710711
shape.block_indent(0)
711712
} else {
712713
shape.block_indent(context.config.tab_spaces())
713-
}.with_max_width(context.config),
714+
}
715+
.with_max_width(context.config),
714716
)
715717
}
716718

src/closures.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ fn rewrite_closure_expr(
198198
} else {
199199
Some(rw)
200200
}
201-
}).map(|rw| format!("{} {}", prefix, rw))
201+
})
202+
.map(|rw| format!("{} {}", prefix, rw))
202203
}
203204

204205
// Rewrite closure whose body is block.
@@ -367,8 +368,10 @@ where
367368
.map(|e| match e.node {
368369
ast::ExprKind::Closure(..) => true,
369370
_ => false,
370-
}).unwrap_or(false)
371-
}).count()
371+
})
372+
.unwrap_or(false)
373+
})
374+
.count()
372375
> 1
373376
}
374377

src/comment.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ fn rewrite_comment_inner(
370370
}
371371

372372
line
373-
}).map(|s| left_trim_comment_line(s, &style))
373+
})
374+
.map(|s| left_trim_comment_line(s, &style))
374375
.map(|(line, has_leading_whitespace)| {
375376
if orig.starts_with("/*") && line_breaks == 0 {
376377
(
@@ -542,7 +543,8 @@ fn trim_custom_comment_prefix(s: &str) -> String {
542543
} else {
543544
line
544545
}
545-
}).collect::<Vec<_>>()
546+
})
547+
.collect::<Vec<_>>()
546548
.join("\n")
547549
}
548550

@@ -630,7 +632,8 @@ fn light_rewrite_comment(
630632
};
631633
// Preserve markdown's double-space line break syntax in doc comment.
632634
trim_right_unless_two_whitespaces(left_trimmed, is_doc_comment)
633-
}).collect();
635+
})
636+
.collect();
634637
Some(lines.join(&format!("\n{}", offset.to_string(config))))
635638
}
636639

@@ -1455,7 +1458,8 @@ mod test {
14551458
.filter_map(|(s, c)| match s {
14561459
FullCodeCharKind::Normal | FullCodeCharKind::InString => Some(c),
14571460
_ => None,
1458-
}).collect()
1461+
})
1462+
.collect()
14591463
}
14601464

14611465
#[test]

src/config/file_lines.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ impl FileLines {
216216
.map(|(file, range)| JsonSpan {
217217
file: file.to_owned(),
218218
range: (range.lo, range.hi),
219-
}).collect(),
219+
})
220+
.collect(),
220221
}
221222
}
222223

src/config/options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,8 @@ impl IgnoreList {
394394
path.push(s);
395395
path
396396
}
397-
}).collect();
397+
})
398+
.collect();
398399
}
399400

400401
fn skip_file_inner(&self, file: &Path) -> bool {

src/expr.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ impl<'a> Rewrite for ControlFlow<'a> {
10291029
false,
10301030
true,
10311031
mk_sp(else_block.span.lo(), self.span.hi()),
1032-
).rewrite(context, shape)
1032+
)
1033+
.rewrite(context, shape)
10331034
}
10341035
ast::ExprKind::If(ref cond, ref if_block, ref next_else_block) => {
10351036
ControlFlow::new_if(
@@ -1040,7 +1041,8 @@ impl<'a> Rewrite for ControlFlow<'a> {
10401041
false,
10411042
true,
10421043
mk_sp(else_block.span.lo(), self.span.hi()),
1043-
).rewrite(context, shape)
1044+
)
1045+
.rewrite(context, shape)
10441046
}
10451047
_ => {
10461048
last_in_chain = true;
@@ -1237,7 +1239,8 @@ fn rewrite_string_lit(context: &RewriteContext, span: Span, shape: Shape) -> Opt
12371239
new_indent.to_string(context.config),
12381240
line.trim_left()
12391241
)
1240-
}).collect::<Vec<_>>()
1242+
})
1243+
.collect::<Vec<_>>()
12411244
.join("\n")
12421245
.trim_left(),
12431246
);

src/formatting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,8 @@ impl FormattingError {
240240
fl.file
241241
.get_line(fl.lines[0].line_index)
242242
.map(|l| l.into_owned())
243-
}).unwrap_or_else(String::new),
243+
})
244+
.unwrap_or_else(String::new),
244245
}
245246
}
246247

src/git-rustfmt/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ fn prune_files(files: Vec<&str>) -> Vec<&str> {
4646
return true;
4747
}
4848
pruned_prefixes.iter().all(|pp| !f.starts_with(pp))
49-
}).collect()
49+
})
50+
.collect()
5051
}
5152

5253
fn git_diff(commits: &str) -> String {

src/imports.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ impl<'a> FmtVisitor<'a> {
4444
Some(item.vis.clone()),
4545
Some(item.span.lo()),
4646
Some(item.attrs.clone()),
47-
).rewrite_top_level(&self.get_context(), shape);
47+
)
48+
.rewrite_top_level(&self.get_context(), shape);
4849
match rw {
4950
Some(ref s) if s.is_empty() => {
5051
// Format up to last newline
@@ -291,7 +292,8 @@ impl UseTree {
291292
} else {
292293
Some(item.attrs.clone())
293294
},
294-
).normalize(),
295+
)
296+
.normalize(),
295297
),
296298
_ => None,
297299
}
@@ -345,13 +347,15 @@ impl UseTree {
345347
context.snippet_provider.span_after(a.span, "{"),
346348
a.span.hi(),
347349
false,
348-
).collect();
350+
)
351+
.collect();
349352
result.path.push(UseSegment::List(
350353
list.iter()
351354
.zip(items.into_iter())
352355
.map(|(t, list_item)| {
353356
Self::from_ast(context, &t.0, Some(list_item), None, None, None)
354-
}).collect(),
357+
})
358+
.collect(),
355359
));
356360
}
357361
UseTreeKind::Simple(ref rename, ..) => {

src/items.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,8 @@ impl<'a> FmtVisitor<'a> {
460460
self.block_indent,
461461
mk_sp(span.lo(), body_start),
462462
last_line_width(&enum_header),
463-
).unwrap();
463+
)
464+
.unwrap();
464465
self.push_str(&generics_str);
465466

466467
self.last_pos = body_start;
@@ -517,7 +518,8 @@ impl<'a> FmtVisitor<'a> {
517518
body_lo,
518519
body_hi,
519520
false,
520-
).collect()
521+
)
522+
.collect()
521523
};
522524
let mut items: Vec<_> =
523525
itemize_list_with(self.config.width_heuristics().struct_variant_width);
@@ -1705,7 +1707,8 @@ fn rewrite_static(
17051707
lhs,
17061708
&**expr,
17071709
Shape::legacy(remaining_width, offset.block_only()),
1708-
).and_then(|res| recover_comment_removed(res, static_parts.span, context))
1710+
)
1711+
.and_then(|res| recover_comment_removed(res, static_parts.span, context))
17091712
.map(|s| if s.ends_with(';') { s } else { s + ";" })
17101713
} else {
17111714
Some(format!("{}{};", prefix, ty_str))
@@ -2233,7 +2236,8 @@ fn rewrite_args(
22332236
.map(|arg| {
22342237
arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
22352238
.unwrap_or_else(|| context.snippet(arg.span()).to_owned())
2236-
}).collect::<Vec<_>>();
2239+
})
2240+
.collect::<Vec<_>>();
22372241

22382242
// Account for sugary self.
22392243
// FIXME: the comment for the self argument is dropped. This is blocked
@@ -2815,7 +2819,8 @@ impl Rewrite for ast::ForeignItem {
28152819
span,
28162820
false,
28172821
false,
2818-
).map(|(s, _)| format!("{};", s)),
2822+
)
2823+
.map(|(s, _)| format!("{};", s)),
28192824
ast::ForeignItemKind::Static(ref ty, is_mutable) => {
28202825
// FIXME(#21): we're dropping potential comments in between the
28212826
// function keywords here.

src/macros.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ pub fn rewrite_macro_inner(
287287
} else {
288288
Some(SeparatorTactic::Never)
289289
},
290-
).map(|rw| match position {
290+
)
291+
.map(|rw| match position {
291292
MacroPosition::Item => format!("{};", rw),
292293
_ => rw,
293294
})
@@ -418,7 +419,8 @@ pub fn rewrite_macro_def(
418419
context.snippet_provider.span_after(span, "{"),
419420
span.hi(),
420421
false,
421-
).collect::<Vec<_>>();
422+
)
423+
.collect::<Vec<_>>();
422424

423425
let fmt = ListFormatting::new(arm_shape, context.config)
424426
.separator(if def.legacy { ";" } else { "" })
@@ -1141,7 +1143,8 @@ fn indent_macro_snippet(
11411143
FullCodeCharKind::InString | FullCodeCharKind::EndString => None,
11421144
_ => prefix_space_width,
11431145
}
1144-
}).min()?;
1146+
})
1147+
.min()?;
11451148

11461149
Some(
11471150
first_line + "\n" + &trimmed_lines
@@ -1157,7 +1160,8 @@ fn indent_macro_snippet(
11571160
}
11581161
None => String::new(),
11591162
},
1160-
).collect::<Vec<_>>()
1163+
)
1164+
.collect::<Vec<_>>()
11611165
.join("\n"),
11621166
)
11631167
}
@@ -1322,7 +1326,8 @@ impl MacroBranch {
13221326
}
13231327
(s + l + "\n", !kind.is_string() || l.ends_with('\\'))
13241328
},
1325-
).0;
1329+
)
1330+
.0;
13261331

13271332
// Undo our replacement of macro variables.
13281333
// FIXME: this could be *much* more efficient.

src/overflow.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ where
5252
item_max_width,
5353
force_separator_tactic,
5454
None,
55-
).rewrite(shape)
55+
)
56+
.rewrite(shape)
5657
}
5758

5859
pub fn rewrite_with_angle_brackets<T>(
@@ -76,7 +77,8 @@ where
7677
context.config.max_width(),
7778
None,
7879
None,
79-
).rewrite(shape)
80+
)
81+
.rewrite(shape)
8082
}
8183

8284
pub fn rewrite_with_square_brackets<T>(
@@ -107,7 +109,8 @@ where
107109
context.config.width_heuristics().array_width,
108110
force_separator_tactic,
109111
Some(("[", "]")),
110-
).rewrite(shape)
112+
)
113+
.rewrite(shape)
111114
}
112115

113116
struct Context<'a, T: 'a> {
@@ -242,7 +245,8 @@ impl<'a, T: 'a + Rewrite + ToExpr + Spanned> Context<'a, T> {
242245
list_items,
243246
self.one_line_shape,
244247
self.item_max_width,
245-
).and_then(|arg_shape| {
248+
)
249+
.and_then(|arg_shape| {
246250
self.rewrite_last_item_with_overflow(
247251
&mut list_items[self.items.len() - 1],
248252
arg_shape,
@@ -495,7 +499,8 @@ where
495499
Shape {
496500
width: min(args_max_width, shape.width),
497501
..shape
498-
}.offset_left(offset)
502+
}
503+
.offset_left(offset)
499504
}
500505

501506
fn shape_from_indent_style(

src/pairs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ fn rewrite_pairs_multiline<T: Rewrite>(
124124
let nested_shape = (match context.config.indent_style() {
125125
IndentStyle::Visual => shape.visual_indent(0),
126126
IndentStyle::Block => shape.block_indent(context.config.tab_spaces()),
127-
}).with_max_width(&context.config)
127+
})
128+
.with_max_width(&context.config)
128129
.sub_width(rhs_offset)?;
129130

130131
let indent_str = nested_shape.indent.to_string_with_newline(context.config);

src/patterns.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ fn count_wildcard_suffix_len(
397397
context.snippet_provider.span_after(span, "("),
398398
span.hi() - BytePos(1),
399399
false,
400-
).collect();
400+
)
401+
.collect();
401402

402403
for item in items.iter().rev().take_while(|i| match i.item {
403404
Some(ref internal_string) if internal_string == "_" => true,

0 commit comments

Comments
 (0)