@@ -18,7 +18,7 @@ use crate::config::lists::*;
1818use crate :: config:: { BraceStyle , Config , IndentStyle , Version } ;
1919use crate :: expr:: {
2020 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 ,
2222} ;
2323use crate :: lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , Separator } ;
2424use crate :: macros:: { rewrite_macro, MacroPosition } ;
@@ -44,7 +44,7 @@ fn type_annotation_separator(config: &Config) -> &str {
4444}
4545
4646// Statements of the form
47- // let pat: ty = init;
47+ // let pat: ty = init; or let pat: ty = init else { .. };
4848impl Rewrite for ast:: Local {
4949 fn rewrite ( & self , context : & RewriteContext < ' _ > , shape : Shape ) -> Option < String > {
5050 debug ! (
@@ -54,7 +54,7 @@ impl Rewrite for ast::Local {
5454
5555 skip_out_of_file_lines_range ! ( context, self . span) ;
5656
57- if contains_skip ( & self . attrs ) || matches ! ( self . kind , ast :: LocalKind :: InitElse ( .. ) ) {
57+ if contains_skip ( & self . attrs ) {
5858 return None ;
5959 }
6060
@@ -112,7 +112,7 @@ impl Rewrite for ast::Local {
112112
113113 result. push_str ( & infix) ;
114114
115- if let Some ( ( init, _els ) ) = self . kind . init_else_opt ( ) {
115+ if let Some ( ( init, else_block ) ) = self . kind . init_else_opt ( ) {
116116 // 1 = trailing semicolon;
117117 let nested_shape = shape. sub_width ( 1 ) ?;
118118
@@ -123,7 +123,17 @@ impl Rewrite for ast::Local {
123123 & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
124124 nested_shape,
125125 ) ?;
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+ } ;
127137 }
128138
129139 result. push ( ';' ) ;
0 commit comments