Skip to content

Commit 2a4d9b0

Browse files
committed
fix if as subexpr
1 parent e110d95 commit 2a4d9b0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/expr.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,12 @@ impl Rewrite for ast::Stmt {
545545
};
546546

547547
let shape = shape.sub_width(suffix.len())?;
548-
format_expr(ex, ExprType::Statement, context, shape).map(|s| s + suffix)
548+
let expr_type = if stmt_is_expr(&self) {
549+
ExprType::SubExpression
550+
} else {
551+
ExprType::Statement
552+
};
553+
format_expr(ex, expr_type, context, shape).map(|s| s + suffix)
549554
}
550555
ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None,
551556
};
@@ -634,11 +639,7 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow>
634639
}
635640

636641
fn choose_matcher(pats: &[&ast::Pat]) -> &'static str {
637-
if pats.is_empty() {
638-
""
639-
} else {
640-
"let"
641-
}
642+
if pats.is_empty() { "" } else { "let" }
642643
}
643644

644645
impl<'a> ControlFlow<'a> {

0 commit comments

Comments
 (0)