@@ -20,10 +20,13 @@ impl Format for IfExpr {
2020 Self :: open_curly_brace ( formatted_code, formatter) ?;
2121 self . then_block . get ( ) . format ( formatted_code, formatter) ?;
2222 Self :: close_curly_brace ( formatted_code, formatter) ?;
23- if let Some ( else_opt) = & self . else_opt {
24- write ! ( formatted_code, "{} " , else_opt. 0 . span( ) . as_str( ) ) ?;
25- match & else_opt. 1 {
26- ControlFlow :: Continue ( if_expr) => if_expr. format ( formatted_code, formatter) ?,
23+ if let Some ( ( else_token, control_flow) ) = & self . else_opt {
24+ write ! ( formatted_code, " {}" , else_token. span( ) . as_str( ) ) ?;
25+ match & control_flow {
26+ ControlFlow :: Continue ( if_expr) => {
27+ write ! ( formatted_code, " " ) ?;
28+ if_expr. format ( formatted_code, formatter) ?
29+ }
2730 ControlFlow :: Break ( code_block_contents) => {
2831 Self :: open_curly_brace ( formatted_code, formatter) ?;
2932 code_block_contents
@@ -41,16 +44,25 @@ impl Format for IfExpr {
4144impl CurlyBrace for IfExpr {
4245 fn open_curly_brace (
4346 line : & mut FormattedCode ,
44- _formatter : & mut Formatter ,
47+ formatter : & mut Formatter ,
4548 ) -> Result < ( ) , FormatterError > {
46- write ! ( line, "{}" , Delimiter :: Brace . as_open_char( ) ) ?;
49+ formatter. shape . block_indent ( & formatter. config ) ;
50+ write ! ( line, " {}" , Delimiter :: Brace . as_open_char( ) ) ?;
51+
4752 Ok ( ( ) )
4853 }
4954 fn close_curly_brace (
5055 line : & mut FormattedCode ,
51- _formatter : & mut Formatter ,
56+ formatter : & mut Formatter ,
5257 ) -> Result < ( ) , FormatterError > {
53- write ! ( line, "{}" , Delimiter :: Brace . as_close_char( ) ) ?;
58+ formatter. shape . block_unindent ( & formatter. config ) ;
59+ write ! (
60+ line,
61+ "{}{}" ,
62+ formatter. shape. indent. to_string( & formatter. config) ?,
63+ Delimiter :: Brace . as_close_char( )
64+ ) ?;
65+
5466 Ok ( ( ) )
5567 }
5668}
@@ -71,7 +83,7 @@ impl Format for IfCondition {
7183 eq_token,
7284 rhs,
7385 } => {
74- write ! ( formatted_code, "{} " , let_token. span( ) . as_str( ) ) ?;
86+ write ! ( formatted_code, " {} " , let_token. span( ) . as_str( ) ) ?;
7587 lhs. format ( formatted_code, formatter) ?;
7688 write ! ( formatted_code, " {} " , eq_token. span( ) . as_str( ) ) ?;
7789 rhs. format ( formatted_code, formatter) ?;
0 commit comments