@@ -18,8 +18,8 @@ use crate::formatting::{
1818        FindUncommented , 
1919    } , 
2020    expr:: { 
21-         is_empty_block,  is_simple_block_stmt,  rewrite_assign_rhs,  rewrite_assign_rhs_expr , 
22-         rewrite_assign_rhs_with ,   rewrite_assign_rhs_with_comments,  RhsTactics , 
21+         is_empty_block,  is_simple_block_stmt,  rewrite_assign_rhs,  rewrite_assign_rhs_with , 
22+         rewrite_assign_rhs_with_comments,  RhsTactics , 
2323    } , 
2424    lists:: { definitive_tactic,  itemize_list,  write_list,  ListFormatting ,  Separator } , 
2525    macros:: { rewrite_macro,  MacroPosition } , 
@@ -121,61 +121,50 @@ impl Rewrite for ast::Local {
121121                mk_sp ( self . pat . span . hi ( ) ,  self . span . hi ( ) ) 
122122            } ; 
123123
124-             if   let  Some ( offset)  = context. snippet ( base_span) . find_uncommented ( "=" )   { 
125-                  let  base_span_lo = base_span. lo ( ) ; 
124+             let  offset = context. snippet ( base_span) . find_uncommented ( "=" ) ? ; 
125+             let  base_span_lo = base_span. lo ( ) ; 
126126
127-                 let  assign_lo = base_span_lo + BytePos ( offset as  u32 ) ; 
128-                 let  comment_start_pos = if  let  Some ( ref  ty)  = self . ty  { 
129-                     ty. span . hi ( ) 
130-                 }  else  { 
131-                     self . pat . span . hi ( ) 
132-                 } ; 
133-                 let  comment_before_assign =
134-                     context. snippet ( mk_sp ( comment_start_pos,  assign_lo) ) . trim ( ) ; 
127+             let  assign_lo = base_span_lo + BytePos ( offset as  u32 ) ; 
128+             let  comment_start_pos = if  let  Some ( ref  ty)  = self . ty  { 
129+                 ty. span . hi ( ) 
130+             }  else  { 
131+                 self . pat . span . hi ( ) 
132+             } ; 
133+             let  comment_before_assign = context. snippet ( mk_sp ( comment_start_pos,  assign_lo) ) . trim ( ) ; 
135134
136-                 let  assign_hi = base_span_lo + BytePos ( ( offset + 1 )  as  u32 ) ; 
137-                 let  rhs_span_lo = ex. span . lo ( ) ; 
138-                 let  comment_end_pos = if  ex. attrs . is_empty ( )  { 
135+             let  assign_hi = base_span_lo + BytePos ( ( offset + 1 )  as  u32 ) ; 
136+             let  rhs_span_lo = ex. span . lo ( ) ; 
137+             let  comment_end_pos = if  ex. attrs . is_empty ( )  { 
138+                 rhs_span_lo
139+             }  else  { 
140+                 let  attr_span_lo = ex. attrs . first ( ) . unwrap ( ) . span . lo ( ) ; 
141+                 // for the case using block 
142+                 // ex. let x = { #![my_attr]do_something(); } 
143+                 if  rhs_span_lo < attr_span_lo { 
139144                    rhs_span_lo
140145                }  else  { 
141-                     let  attr_span_lo = ex. attrs . first ( ) . unwrap ( ) . span . lo ( ) ; 
142-                     // for the case using block 
143-                     // ex. let x = { #![my_attr]do_something(); } 
144-                     if  rhs_span_lo < attr_span_lo { 
145-                         rhs_span_lo
146-                     }  else  { 
147-                         attr_span_lo
148-                     } 
149-                 } ; 
150-                 let  comment_after_assign =
151-                     context. snippet ( mk_sp ( assign_hi,  comment_end_pos) ) . trim ( ) ; 
152- 
153-                 if  !comment_before_assign. is_empty ( )  { 
154-                     let  new_indent_str = & pat_shape
155-                         . block_indent ( 0 ) 
156-                         . to_string_with_newline ( context. config ) ; 
157-                     result = format ! ( "{}{}{}" ,  comment_before_assign,  new_indent_str,  result) ; 
146+                     attr_span_lo
158147                } 
148+             } ; 
159149
160-                 if  !comment_after_assign. is_empty ( )  { 
161-                     let  new_indent_str =
162-                         & shape. block_indent ( 0 ) . to_string_with_newline ( context. config ) ; 
163-                     result. push_str ( new_indent_str) ; 
164-                     result. push_str ( comment_after_assign) ; 
165-                     result. push_str ( new_indent_str) ; 
166-                 } 
150+             if  !comment_before_assign. is_empty ( )  { 
151+                 let  new_indent_str = & pat_shape
152+                     . block_indent ( 0 ) 
153+                     . to_string_with_newline ( context. config ) ; 
154+                 result = format ! ( "{}{}{}" ,  comment_before_assign,  new_indent_str,  result) ; 
167155            } 
168156
169157            // 1 = trailing semicolon; 
170158            let  nested_shape = shape. sub_width ( 1 ) ?; 
171-             let  rhs =  rewrite_assign_rhs_expr ( 
159+             result =  rewrite_assign_rhs_with_comments ( 
172160                context, 
173161                & result, 
174162                & * * ex, 
175163                nested_shape, 
176164                RhsTactics :: Default , 
165+                 mk_sp ( assign_hi,  comment_end_pos) , 
166+                 true , 
177167            ) ?; 
178-             result = result + & rhs; 
179168        } 
180169
181170        result. push ( ';' ) ; 
0 commit comments