Skip to content

Commit d08ddbe

Browse files
committed
fix if as subexpr
1 parent 8298f25 commit d08ddbe

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
@@ -710,7 +710,12 @@ impl Rewrite for ast::Stmt {
710710
};
711711

712712
let shape = shape.sub_width(suffix.len())?;
713-
format_expr(ex, ExprType::Statement, context, shape).map(|s| s + suffix)
713+
let expr_type = if stmt_is_expr(&self) {
714+
ExprType::SubExpression
715+
} else {
716+
ExprType::Statement
717+
};
718+
format_expr(ex, expr_type, context, shape).map(|s| s + suffix)
714719
}
715720
ast::StmtKind::Mac(..) | ast::StmtKind::Item(..) => None,
716721
};
@@ -799,11 +804,7 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow>
799804
}
800805

801806
fn choose_matcher(pats: &[&ast::Pat]) -> &'static str {
802-
if pats.is_empty() {
803-
""
804-
} else {
805-
"let"
806-
}
807+
if pats.is_empty() { "" } else { "let" }
807808
}
808809

809810
impl<'a> ControlFlow<'a> {

0 commit comments

Comments
 (0)