@@ -18,7 +18,7 @@ use crate::config::lists::*;
18
18
use crate :: config:: { BraceStyle , Config , IndentStyle , Version } ;
19
19
use crate :: expr:: {
20
20
is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
21
- rewrite_assign_rhs_with_comments, RhsAssignKind , RhsTactics ,
21
+ rewrite_assign_rhs_with_comments, rewrite_else_kw_with_comments , RhsAssignKind , RhsTactics ,
22
22
} ;
23
23
use crate :: lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , Separator } ;
24
24
use crate :: macros:: { rewrite_macro, MacroPosition } ;
@@ -44,7 +44,7 @@ fn type_annotation_separator(config: &Config) -> &str {
44
44
}
45
45
46
46
// Statements of the form
47
- // let pat: ty = init;
47
+ // let pat: ty = init; or let pat: ty = init else { .. };
48
48
impl Rewrite for ast:: Local {
49
49
fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
50
50
debug ! (
@@ -54,7 +54,7 @@ impl Rewrite for ast::Local {
54
54
55
55
skip_out_of_file_lines_range ! ( context, self . span) ;
56
56
57
- if contains_skip ( & self . attrs ) || matches ! ( self . kind , ast :: LocalKind :: InitElse ( .. ) ) {
57
+ if contains_skip ( & self . attrs ) {
58
58
return None ;
59
59
}
60
60
@@ -112,7 +112,7 @@ impl Rewrite for ast::Local {
112
112
113
113
result. push_str ( & infix) ;
114
114
115
- if let Some ( ( init, _els ) ) = self . kind . init_else_opt ( ) {
115
+ if let Some ( ( init, else_block ) ) = self . kind . init_else_opt ( ) {
116
116
// 1 = trailing semicolon;
117
117
let nested_shape = shape. sub_width ( 1 ) ?;
118
118
@@ -123,7 +123,17 @@ impl Rewrite for ast::Local {
123
123
& RhsAssignKind :: Expr ( & init. kind , init. span ) ,
124
124
nested_shape,
125
125
) ?;
126
- // todo else
126
+
127
+ if let Some ( block) = else_block {
128
+ let else_kw = rewrite_else_kw_with_comments (
129
+ true ,
130
+ context,
131
+ init. span . between ( block. span ) ,
132
+ shape,
133
+ ) ;
134
+ result. push_str ( & else_kw) ;
135
+ result. push_str ( & block. rewrite ( context, shape) ?) ;
136
+ } ;
127
137
}
128
138
129
139
result. push ( ';' ) ;
0 commit comments