@@ -110,12 +110,11 @@ pub(crate) fn format_expr(
110
110
ast:: ExprKind :: Tup ( ref items) => {
111
111
rewrite_tuple ( context, items. iter ( ) , expr. span , shape, items. len ( ) == 1 )
112
112
}
113
+ ast:: ExprKind :: Let ( ..) => None ,
113
114
ast:: ExprKind :: If ( ..)
114
- | ast:: ExprKind :: IfLet ( ..)
115
115
| ast:: ExprKind :: ForLoop ( ..)
116
116
| 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)
119
118
. and_then ( |control_flow| control_flow. rewrite ( context, shape) ) ,
120
119
ast:: ExprKind :: Block ( ref block, opt_label) => {
121
120
match expr_type {
@@ -610,21 +609,21 @@ struct ControlFlow<'a> {
610
609
span : Span ,
611
610
}
612
611
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.
613
620
fn to_control_flow ( expr : & ast:: Expr , expr_type : ExprType ) -> Option < ControlFlow < ' _ > > {
614
621
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) ;
625
624
Some ( ControlFlow :: new_if (
626
625
cond,
627
- ptr_vec_to_ref_vec ( pat ) ,
626
+ pats ,
628
627
if_block,
629
628
else_block. as_ref ( ) . map ( |e| & * * e) ,
630
629
expr_type == ExprType :: SubExpression ,
@@ -638,16 +637,10 @@ fn to_control_flow(expr: &ast::Expr, expr_type: ExprType) -> Option<ControlFlow<
638
637
ast:: ExprKind :: Loop ( ref block, label) => {
639
638
Some ( ControlFlow :: new_loop ( block, label, expr. span ) )
640
639
}
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
+ }
651
644
_ => None ,
652
645
}
653
646
}
@@ -1020,22 +1013,11 @@ impl<'a> Rewrite for ControlFlow<'a> {
1020
1013
// from being formatted on a single line.
1021
1014
// Note how we're passing the original shape, as the
1022
1015
// 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
- }
1035
1016
ast:: ExprKind :: If ( ref cond, ref if_block, ref next_else_block) => {
1017
+ let ( pats, cond) = extract_pats_and_cond ( cond) ;
1036
1018
ControlFlow :: new_if (
1037
1019
cond,
1038
- vec ! [ ] ,
1020
+ pats ,
1039
1021
if_block,
1040
1022
next_else_block. as_ref ( ) . map ( |e| & * * e) ,
1041
1023
false ,
@@ -1332,11 +1314,9 @@ pub(crate) fn can_be_overflowed_expr(
1332
1314
|| context. config . overflow_delimited_expr ( )
1333
1315
}
1334
1316
ast:: ExprKind :: If ( ..)
1335
- | ast:: ExprKind :: IfLet ( ..)
1336
1317
| ast:: ExprKind :: ForLoop ( ..)
1337
1318
| ast:: ExprKind :: Loop ( ..)
1338
- | ast:: ExprKind :: While ( ..)
1339
- | ast:: ExprKind :: WhileLet ( ..) => {
1319
+ | ast:: ExprKind :: While ( ..) => {
1340
1320
context. config . combine_control_expr ( ) && context. use_block_indent ( ) && args_len == 1
1341
1321
}
1342
1322
0 commit comments