Skip to content

Commit a42f9f2

Browse files
committed
Format
1 parent 79f4dec commit a42f9f2

File tree

6 files changed

+45
-35
lines changed

6 files changed

+45
-35
lines changed

src/chains.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,12 @@ fn is_extendable_parent(context: &RewriteContext, parent_str: &str) -> bool {
269269

270270
// True if the chain is only `?`s.
271271
fn chain_only_try(exprs: &[ast::Expr]) -> bool {
272-
exprs.iter().all(|e| if let ast::ExprKind::Try(_) = e.node {
273-
true
274-
} else {
275-
false
272+
exprs.iter().all(|e| {
273+
if let ast::ExprKind::Try(_) = e.node {
274+
true
275+
} else {
276+
false
277+
}
276278
})
277279
}
278280

src/comment.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ fn rewrite_comment_inner(
320320
line
321321
})
322322
.map(|s| left_trim_comment_line(s, &style))
323-
.map(|line| if orig.starts_with("/*") && line_breaks == 0 {
324-
line.trim_left()
325-
} else {
326-
line
323+
.map(|line| {
324+
if orig.starts_with("/*") && line_breaks == 0 {
325+
line.trim_left()
326+
} else {
327+
line
328+
}
327329
});
328330

329331
let mut result = opener.to_owned();

src/expr.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,13 +1205,13 @@ impl<'a> ControlFlow<'a> {
12051205
context
12061206
.codemap
12071207
.span_after(mk_sp(lo, self.span.hi), self.keyword.trim()),
1208-
self.pat
1209-
.map_or(cond_span.lo, |p| if self.matcher.is_empty() {
1208+
self.pat.map_or(cond_span.lo, |p| {
1209+
if self.matcher.is_empty() {
12101210
p.span.lo
12111211
} else {
12121212
context.codemap.span_before(self.span, self.matcher.trim())
1213-
},
1214-
),
1213+
}
1214+
}),
12151215
);
12161216

12171217
let between_kwd_cond_comment = extract_comment(between_kwd_cond, context, shape);

src/types.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,12 @@ impl Rewrite for ast::Ty {
707707
ast::TyKind::Paren(ref ty) => {
708708
let budget = try_opt!(shape.width.checked_sub(2));
709709
ty.rewrite(context, Shape::legacy(budget, shape.indent + 1))
710-
.map(|ty_str| if context.config.spaces_within_parens() {
711-
format!("( {} )", ty_str)
712-
} else {
713-
format!("({})", ty_str)
710+
.map(|ty_str| {
711+
if context.config.spaces_within_parens() {
712+
format!("( {} )", ty_str)
713+
} else {
714+
format!("({})", ty_str)
715+
}
714716
})
715717
}
716718
ast::TyKind::Slice(ref ty) => {
@@ -720,10 +722,12 @@ impl Rewrite for ast::Ty {
720722
try_opt!(shape.width.checked_sub(2))
721723
};
722724
ty.rewrite(context, Shape::legacy(budget, shape.indent + 1))
723-
.map(|ty_str| if context.config.spaces_within_square_brackets() {
724-
format!("[ {} ]", ty_str)
725-
} else {
726-
format!("[{}]", ty_str)
725+
.map(|ty_str| {
726+
if context.config.spaces_within_square_brackets() {
727+
format!("[ {} ]", ty_str)
728+
} else {
729+
format!("[{}]", ty_str)
730+
}
727731
})
728732
}
729733
ast::TyKind::Tup(ref items) => rewrite_tuple(

src/vertical.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,13 @@ fn struct_field_preix_max_min_width<T: AlignedItem>(
199199
fields
200200
.iter()
201201
.map(|field| {
202-
field
203-
.rewrite_prefix(context, shape)
204-
.and_then(|field_str| if field_str.contains('\n') {
202+
field.rewrite_prefix(context, shape).and_then(|field_str| {
203+
if field_str.contains('\n') {
205204
None
206205
} else {
207206
Some(field_str.len())
208-
})
207+
}
208+
})
209209
})
210210
.fold(Some((0, ::std::usize::MAX)), |acc, len| match (acc, len) {
211211
(Some((max_len, min_len)), Some(len)) => {

src/visitor.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,15 @@ impl<'a> FmtVisitor<'a> {
163163

164164
let snippet =
165165
self.snippet(mk_sp(self.last_pos, attr_lo.unwrap_or(first_stmt.span.lo)));
166-
let len = CommentCodeSlices::new(&snippet).nth(0).and_then(
167-
|(kind, _, s)| if kind == CodeCharKind::Normal {
168-
s.rfind('\n')
169-
} else {
170-
None
171-
},
172-
);
166+
let len = CommentCodeSlices::new(&snippet)
167+
.nth(0)
168+
.and_then(|(kind, _, s)| {
169+
if kind == CodeCharKind::Normal {
170+
s.rfind('\n')
171+
} else {
172+
None
173+
}
174+
});
173175
if let Some(len) = len {
174176
self.last_pos = self.last_pos + BytePos::from_usize(len);
175177
}
@@ -899,9 +901,8 @@ impl Rewrite for ast::MetaItem {
899901

900902
impl Rewrite for ast::Attribute {
901903
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
902-
try_opt!(self.meta())
903-
.rewrite(context, shape)
904-
.map(|rw| if self.is_sugared_doc {
904+
try_opt!(self.meta()).rewrite(context, shape).map(|rw| {
905+
if self.is_sugared_doc {
905906
rw
906907
} else {
907908
let original = context.snippet(self.span);
@@ -914,7 +915,8 @@ impl Rewrite for ast::Attribute {
914915
} else {
915916
format!("{}[{}]", prefix, rw)
916917
}
917-
})
918+
}
919+
})
918920
}
919921
}
920922

0 commit comments

Comments
 (0)