Skip to content

Commit f7ba2db

Browse files
workingjubileecalebcartwright
authored andcommitted
Clarify conditionals for clippy
Remove double-check of is_mod in format_extern Collapse nested if in is_block_closure_forced Use map instead of and_then in rewrite_last_closure Collapse nested if in impl Rewrite for ast::Ty Collapse nested if in format_expr Collapse nested if in merge_use_trees_inner
1 parent cd1549f commit f7ba2db

File tree

5 files changed

+24
-28
lines changed

5 files changed

+24
-28
lines changed

Diff for: src/formatting/closures.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -364,20 +364,20 @@ pub(crate) fn rewrite_last_closure(
364364

365365
// We force to use block for the body of the closure for certain kinds of expressions.
366366
if is_block_closure_forced(context, body, capture) {
367-
return rewrite_closure_with_block(body, &prefix, context, body_shape).and_then(
367+
return rewrite_closure_with_block(body, &prefix, context, body_shape).map(
368368
|body_str| {
369369
// If the expression can fit in a single line, we need not force block closure.
370370
if body_str.lines().count() <= 7 {
371371
match rewrite_closure_expr(body, &prefix, context, shape) {
372372
Some(ref single_line_body_str)
373373
if !single_line_body_str.contains('\n') =>
374374
{
375-
Some(single_line_body_str.clone())
375+
single_line_body_str.clone()
376376
}
377-
_ => Some(body_str),
377+
_ => body_str,
378378
}
379379
} else {
380-
Some(body_str)
380+
body_str
381381
}
382382
},
383383
);
@@ -415,15 +415,13 @@ fn is_block_closure_forced(
415415
// If we are inside macro, we do not want to add or remove block from closure body.
416416
if context.inside_macro() {
417417
false
418-
} else {
419-
if let ast::ExprKind::Match(..) = expr.kind {
420-
let is_move_closure_without_brace = capture == ast::CaptureBy::Value
421-
&& !context.snippet(expr.span).trim().starts_with('{');
418+
} else if let ast::ExprKind::Match(..) = expr.kind {
419+
let is_move_closure_without_brace =
420+
capture == ast::CaptureBy::Value && !context.snippet(expr.span).trim().starts_with('{');
422421

423-
is_block_closure_forced_inner(expr) || is_move_closure_without_brace
424-
} else {
425-
is_block_closure_forced_inner(expr)
426-
}
422+
is_block_closure_forced_inner(expr) || is_move_closure_without_brace
423+
} else {
424+
is_block_closure_forced_inner(expr)
427425
}
428426
}
429427

Diff for: src/formatting/expr.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,10 @@ pub(crate) fn format_expr(
8080
ast::ExprKind::Lit(ref l) => {
8181
if let Some(expr_rw) = rewrite_literal(context, l, shape) {
8282
Some(expr_rw)
83+
} else if let LitKind::StrRaw(_) = l.token.kind {
84+
Some(context.snippet(l.span).trim().into())
8385
} else {
84-
if let LitKind::StrRaw(_) = l.token.kind {
85-
Some(context.snippet(l.span).trim().into())
86-
} else {
87-
None
88-
}
86+
None
8987
}
9088
}
9189
ast::ExprKind::Call(ref callee, ref args) => {

Diff for: src/formatting/imports.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -626,12 +626,10 @@ fn merge_use_trees_inner(trees: &mut Vec<UseTree>, use_tree: UseTree) {
626626
return;
627627
}
628628
}
629-
} else {
630-
if let Some(tree) = similar_trees.max_by_key(|tree| tree.path.len()) {
631-
if tree.path.len() > 1 {
632-
tree.merge(&use_tree);
633-
return;
634-
}
629+
} else if let Some(tree) = similar_trees.max_by_key(|tree| tree.path.len()) {
630+
if tree.path.len() > 1 {
631+
tree.merge(&use_tree);
632+
return;
635633
}
636634
}
637635
trees.push(use_tree);

Diff for: src/formatting/types.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -625,10 +625,12 @@ impl Rewrite for ast::Ty {
625625
let shape = if is_dyn { shape.offset_left(4)? } else { shape };
626626
let mut res = bounds.rewrite(context, shape)?;
627627
// We may have falsely removed a trailing `+` inside macro call.
628-
if context.inside_macro() && bounds.len() == 1 {
629-
if context.snippet(self.span).ends_with('+') && !res.ends_with('+') {
630-
res.push('+');
631-
}
628+
if context.inside_macro()
629+
&& bounds.len() == 1
630+
&& context.snippet(self.span).ends_with('+')
631+
&& !res.ends_with('+')
632+
{
633+
res.push('+');
632634
}
633635
if is_dyn {
634636
Some(format!("dyn {}", res))

Diff for: src/formatting/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub(crate) fn format_extern(
154154
) -> Cow<'static, str> {
155155
let format_explicit_abi = |abi: &str| Cow::from(format!(r#"extern "{}" "#, abi));
156156
let explicit_conversion_preserves_semantics =
157-
|| !is_mod || (is_mod && attrs.map_or(true, |a| a.is_empty()));
157+
|| !is_mod || attrs.map_or(true, |a| a.is_empty());
158158

159159
match ext {
160160
ast::Extern::None if !is_mod => Cow::from(""),

0 commit comments

Comments
 (0)