@@ -110,12 +110,11 @@ pub(crate) fn format_expr(
110110 ast:: ExprKind :: Tup ( ref items) => {
111111 rewrite_tuple ( context, items. iter ( ) , expr. span , shape, items. len ( ) == 1 )
112112 }
113+ ast:: ExprKind :: Let ( ..) => None ,
113114 ast:: ExprKind :: If ( ..)
114- | ast:: ExprKind :: IfLet ( ..)
115115 | ast:: ExprKind :: ForLoop ( ..)
116116 | ast:: ExprKind :: Loop ( ..)
117- | ast:: ExprKind :: While ( ..)
118- | ast:: ExprKind :: WhileLet ( ..) => to_control_flow ( expr, expr_type)
117+ | ast:: ExprKind :: While ( ..) => to_control_flow ( expr, expr_type)
119118 . and_then ( |control_flow| control_flow. rewrite ( context, shape) ) ,
120119 ast:: ExprKind :: Block ( ref block, opt_label) => {
121120 match expr_type {
@@ -610,21 +609,21 @@ struct ControlFlow<'a> {
610609 span : Span ,
611610}
612611
612+ fn extract_pats_and_cond ( expr : & ast:: Expr ) -> ( Vec < & ast:: Pat > , & ast:: Expr ) {
613+ match expr. node {
614+ ast:: ExprKind :: Let ( ref pats, ref cond) => ( ptr_vec_to_ref_vec ( pats) , cond) ,
615+ _ => ( vec ! [ ] , expr) ,
616+ }
617+ }
618+
619+ // FIXME: Refactor this.
613620fn to_control_flow ( expr : & ast:: Expr , expr_type : ExprType ) -> Option < ControlFlow < ' _ > > {
614621 match expr. node {
615- ast:: ExprKind :: If ( ref cond, ref if_block, ref else_block) => Some ( ControlFlow :: new_if (
616- cond,
617- vec ! [ ] ,
618- if_block,
619- else_block. as_ref ( ) . map ( |e| & * * e) ,
620- expr_type == ExprType :: SubExpression ,
621- false ,
622- expr. span ,
623- ) ) ,
624- ast:: ExprKind :: IfLet ( ref pat, ref cond, ref if_block, ref else_block) => {
622+ ast:: ExprKind :: If ( ref cond, ref if_block, ref else_block) => {
623+ let ( pats, cond) = extract_pats_and_cond ( cond) ;
625624 Some ( ControlFlow :: new_if (
626625 cond,
627- ptr_vec_to_ref_vec ( pat ) ,
626+ pats ,
628627 if_block,
629628 else_block. as_ref ( ) . map ( |e| & * * e) ,
630629 expr_type == ExprType :: SubExpression ,
@@ -638,16 +637,10 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
638637 ast:: ExprKind :: Loop ( ref block, label) => {
639638 Some ( ControlFlow :: new_loop ( block, label, expr. span ) )
640639 }
641- ast:: ExprKind :: While ( ref cond, ref block, label) => Some ( ControlFlow :: new_while (
642- vec ! [ ] ,
643- cond,
644- block,
645- label,
646- expr. span ,
647- ) ) ,
648- ast:: ExprKind :: WhileLet ( ref pat, ref cond, ref block, label) => Some (
649- ControlFlow :: new_while ( ptr_vec_to_ref_vec ( pat) , cond, block, label, expr. span ) ,
650- ) ,
640+ ast:: ExprKind :: While ( ref cond, ref block, label) => {
641+ let ( pats, cond) = extract_pats_and_cond ( cond) ;
642+ Some ( ControlFlow :: new_while ( pats, cond, block, label, expr. span ) )
643+ }
651644 _ => None ,
652645 }
653646}
@@ -1020,22 +1013,11 @@ impl<'a> Rewrite for ControlFlow<'a> {
10201013 // from being formatted on a single line.
10211014 // Note how we're passing the original shape, as the
10221015 // cost of "else" should not cascade.
1023- ast:: ExprKind :: IfLet ( ref pat, ref cond, ref if_block, ref next_else_block) => {
1024- ControlFlow :: new_if (
1025- cond,
1026- ptr_vec_to_ref_vec ( pat) ,
1027- if_block,
1028- next_else_block. as_ref ( ) . map ( |e| & * * e) ,
1029- false ,
1030- true ,
1031- mk_sp ( else_block. span . lo ( ) , self . span . hi ( ) ) ,
1032- )
1033- . rewrite ( context, shape)
1034- }
10351016 ast:: ExprKind :: If ( ref cond, ref if_block, ref next_else_block) => {
1017+ let ( pats, cond) = extract_pats_and_cond ( cond) ;
10361018 ControlFlow :: new_if (
10371019 cond,
1038- vec ! [ ] ,
1020+ pats ,
10391021 if_block,
10401022 next_else_block. as_ref ( ) . map ( |e| & * * e) ,
10411023 false ,
@@ -1332,11 +1314,9 @@ pub(crate) fn can_be_overflowed_expr(
13321314 || context. config . overflow_delimited_expr ( )
13331315 }
13341316 ast:: ExprKind :: If ( ..)
1335- | ast:: ExprKind :: IfLet ( ..)
13361317 | ast:: ExprKind :: ForLoop ( ..)
13371318 | ast:: ExprKind :: Loop ( ..)
1338- | ast:: ExprKind :: While ( ..)
1339- | ast:: ExprKind :: WhileLet ( ..) => {
1319+ | ast:: ExprKind :: While ( ..) => {
13401320 context. config . combine_control_expr ( ) && context. use_block_indent ( ) && args_len == 1
13411321 }
13421322
0 commit comments