Skip to content

Commit b17de62

Browse files
committed
Cargo fmt
1 parent 960fec8 commit b17de62

File tree

8 files changed

+65
-46
lines changed

8 files changed

+65
-46
lines changed

src/bin/cargo-fmt.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,10 @@ fn format_crate(
133133
let files: Vec<_> = targets
134134
.into_iter()
135135
.filter(|t| t.kind.should_format())
136-
.inspect(|t| if verbosity == Verbosity::Verbose {
137-
println!("[{:?}] {:?}", t.kind, t.path)
136+
.inspect(|t| {
137+
if verbosity == Verbosity::Verbose {
138+
println!("[{:?}] {:?}", t.kind, t.path)
139+
}
138140
})
139141
.map(|t| t.path)
140142
.collect();

src/chains.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,12 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) -
297297

298298
// True if the chain is only `?`s.
299299
fn chain_only_try(exprs: &[ast::Expr]) -> bool {
300-
exprs.iter().all(|e| if let ast::ExprKind::Try(_) = e.node {
301-
true
302-
} else {
303-
false
300+
exprs.iter().all(|e| {
301+
if let ast::ExprKind::Try(_) = e.node {
302+
true
303+
} else {
304+
false
305+
}
304306
})
305307
}
306308

src/comment.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ fn rewrite_comment_inner(
311311
line
312312
})
313313
.map(|s| left_trim_comment_line(s, &style))
314-
.map(|line| if orig.starts_with("/*") && line_breaks == 0 {
315-
line.trim_left()
316-
} else {
317-
line
314+
.map(|line| {
315+
if orig.starts_with("/*") && line_breaks == 0 {
316+
line.trim_left()
317+
} else {
318+
line
319+
}
318320
});
319321

320322
let mut result = opener.to_owned();

src/expr.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,12 +1198,13 @@ impl<'a> ControlFlow<'a> {
11981198
context
11991199
.codemap
12001200
.span_after(mk_sp(lo, self.span.hi()), self.keyword.trim()),
1201-
self.pat
1202-
.map_or(cond_span.lo(), |p| if self.matcher.is_empty() {
1201+
self.pat.map_or(cond_span.lo(), |p| {
1202+
if self.matcher.is_empty() {
12031203
p.span.lo()
12041204
} else {
12051205
context.codemap.span_before(self.span, self.matcher.trim())
1206-
}),
1206+
}
1207+
}),
12071208
);
12081209

12091210
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);
@@ -2753,13 +2754,17 @@ where
27532754
if items.len() == 1 {
27542755
// 3 = "(" + ",)"
27552756
let nested_shape = shape.sub_width(3)?.visual_indent(1);
2756-
return items.next().unwrap().rewrite(context, nested_shape).map(
2757-
|s| if context.config.spaces_within_parens() {
2758-
format!("( {}, )", s)
2759-
} else {
2760-
format!("({},)", s)
2761-
},
2762-
);
2757+
return items
2758+
.next()
2759+
.unwrap()
2760+
.rewrite(context, nested_shape)
2761+
.map(|s| {
2762+
if context.config.spaces_within_parens() {
2763+
format!("( {}, )", s)
2764+
} else {
2765+
format!("({},)", s)
2766+
}
2767+
});
27632768
}
27642769

27652770
let list_lo = context.codemap.span_after(span, "(");

src/types.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -670,10 +670,12 @@ impl Rewrite for ast::Ty {
670670
ast::TyKind::Paren(ref ty) => {
671671
let budget = shape.width.checked_sub(2)?;
672672
ty.rewrite(context, Shape::legacy(budget, shape.indent + 1))
673-
.map(|ty_str| if context.config.spaces_within_parens() {
674-
format!("( {} )", ty_str)
675-
} else {
676-
format!("({})", ty_str)
673+
.map(|ty_str| {
674+
if context.config.spaces_within_parens() {
675+
format!("( {} )", ty_str)
676+
} else {
677+
format!("({})", ty_str)
678+
}
677679
})
678680
}
679681
ast::TyKind::Slice(ref ty) => {
@@ -683,10 +685,12 @@ impl Rewrite for ast::Ty {
683685
shape.width.checked_sub(2)?
684686
};
685687
ty.rewrite(context, Shape::legacy(budget, shape.indent + 1))
686-
.map(|ty_str| if context.config.spaces_within_square_brackets() {
687-
format!("[ {} ]", ty_str)
688-
} else {
689-
format!("[{}]", ty_str)
688+
.map(|ty_str| {
689+
if context.config.spaces_within_square_brackets() {
690+
format!("[ {} ]", ty_str)
691+
} else {
692+
format!("[{}]", ty_str)
693+
}
690694
})
691695
}
692696
ast::TyKind::Tup(ref items) => rewrite_tuple(

src/vertical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ fn struct_field_prefix_max_min_width<T: AlignedItem>(
191191
fields
192192
.iter()
193193
.map(|field| {
194-
field
195-
.rewrite_prefix(context, shape)
196-
.and_then(|field_str| if field_str.contains('\n') {
194+
field.rewrite_prefix(context, shape).and_then(|field_str| {
195+
if field_str.contains('\n') {
197196
None
198197
} else {
199198
Some(field_str.len())
200-
})
199+
}
200+
})
201201
})
202202
.fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
203203
(Some((max_len, min_len)), Some(len)) => {

src/visitor.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,15 @@ impl<'a> FmtVisitor<'a> {
136136
self.last_pos,
137137
attr_lo.unwrap_or(first_stmt.span.lo()),
138138
));
139-
let len = CommentCodeSlices::new(&snippet).nth(0).and_then(
140-
|(kind, _, s)| if kind == CodeCharKind::Normal {
141-
s.rfind('\n')
142-
} else {
143-
None
144-
},
145-
);
139+
let len = CommentCodeSlices::new(&snippet)
140+
.nth(0)
141+
.and_then(|(kind, _, s)| {
142+
if kind == CodeCharKind::Normal {
143+
s.rfind('\n')
144+
} else {
145+
None
146+
}
147+
});
146148
if let Some(len) = len {
147149
self.last_pos = self.last_pos + BytePos::from_usize(len);
148150
}

tests/system.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,17 @@ struct CharsIgnoreNewlineRepr<'a>(Peekable<Chars<'a>>);
446446
impl<'a> Iterator for CharsIgnoreNewlineRepr<'a> {
447447
type Item = char;
448448
fn next(&mut self) -> Option<char> {
449-
self.0.next().map(|c| if c == '\r' {
450-
if *self.0.peek().unwrap_or(&'\0') == '\n' {
451-
self.0.next();
452-
'\n'
449+
self.0.next().map(|c| {
450+
if c == '\r' {
451+
if *self.0.peek().unwrap_or(&'\0') == '\n' {
452+
self.0.next();
453+
'\n'
454+
} else {
455+
'\r'
456+
}
453457
} else {
454-
'\r'
458+
c
455459
}
456-
} else {
457-
c
458460
})
459461
}
460462
}

0 commit comments

Comments
 (0)