@@ -18,8 +18,8 @@ use crate::formatting::{
18
18
FindUncommented ,
19
19
} ,
20
20
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 ,
23
23
} ,
24
24
lists:: { definitive_tactic, itemize_list, write_list, ListFormatting , Separator } ,
25
25
macros:: { rewrite_macro, MacroPosition } ,
@@ -121,61 +121,50 @@ impl Rewrite for ast::Local {
121
121
mk_sp ( self . pat . span . hi ( ) , self . span . hi ( ) )
122
122
} ;
123
123
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 ( ) ;
126
126
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 ( ) ;
135
134
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 {
139
144
rhs_span_lo
140
145
} 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
158
147
}
148
+ } ;
159
149
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) ;
167
155
}
168
156
169
157
// 1 = trailing semicolon;
170
158
let nested_shape = shape. sub_width ( 1 ) ?;
171
- let rhs = rewrite_assign_rhs_expr (
159
+ result = rewrite_assign_rhs_with_comments (
172
160
context,
173
161
& result,
174
162
& * * ex,
175
163
nested_shape,
176
164
RhsTactics :: Default ,
165
+ mk_sp ( assign_hi, comment_end_pos) ,
166
+ true ,
177
167
) ?;
178
- result = result + & rhs;
179
168
}
180
169
181
170
result. push ( ';' ) ;
0 commit comments