@@ -119,62 +119,51 @@ impl Rewrite for ast::Local {
119
119
mk_sp ( self . pat . span . hi ( ) , self . span . hi ( ) )
120
120
} ;
121
121
122
- if let Some ( offset) = context. snippet ( base_span) . find_uncommented ( "=" ) {
123
- let base_span_lo = base_span. lo ( ) ;
122
+ let offset = context. snippet ( base_span) . find_uncommented ( "=" ) ? ;
123
+ let base_span_lo = base_span. lo ( ) ;
124
124
125
- let assign_lo = base_span_lo + BytePos ( offset as u32 ) ;
126
- let comment_start_pos = if let Some ( ref ty) = self . ty {
127
- ty. span . hi ( )
128
- } else {
129
- self . pat . span . hi ( )
130
- } ;
131
- let comment_before_assign =
132
- context. snippet ( mk_sp ( comment_start_pos, assign_lo) ) . trim ( ) ;
125
+ let assign_lo = base_span_lo + BytePos ( offset as u32 ) ;
126
+ let comment_start_pos = if let Some ( ref ty) = self . ty {
127
+ ty. span . hi ( )
128
+ } else {
129
+ self . pat . span . hi ( )
130
+ } ;
131
+ let comment_before_assign = context. snippet ( mk_sp ( comment_start_pos, assign_lo) ) . trim ( ) ;
133
132
134
- let assign_hi = base_span_lo + BytePos ( ( offset + 1 ) as u32 ) ;
135
- let rhs_span_lo = init. span . lo ( ) ;
136
- let comment_end_pos = if init. attrs . is_empty ( ) {
133
+ let assign_hi = base_span_lo + BytePos ( ( offset + 1 ) as u32 ) ;
134
+ let rhs_span_lo = init. span . lo ( ) ;
135
+ let comment_end_pos = if init. attrs . is_empty ( ) {
136
+ rhs_span_lo
137
+ } else {
138
+ let attr_span_lo = init. attrs . first ( ) . unwrap ( ) . span . lo ( ) ;
139
+ // for the case using block
140
+ // ex. let x = { #![my_attr]do_something(); }
141
+ if rhs_span_lo < attr_span_lo {
137
142
rhs_span_lo
138
143
} else {
139
- let attr_span_lo = init. attrs . first ( ) . unwrap ( ) . span . lo ( ) ;
140
- // for the case using block
141
- // ex. let x = { #![my_attr]do_something(); }
142
- if rhs_span_lo < attr_span_lo {
143
- rhs_span_lo
144
- } else {
145
- attr_span_lo
146
- }
147
- } ;
148
- let comment_after_assign =
149
- context. snippet ( mk_sp ( assign_hi, comment_end_pos) ) . trim ( ) ;
150
-
151
- if !comment_before_assign. is_empty ( ) {
152
- let new_indent_str = & pat_shape
153
- . block_indent ( 0 )
154
- . to_string_with_newline ( context. config ) ;
155
- result = format ! ( "{}{}{}" , comment_before_assign, new_indent_str, result) ;
144
+ attr_span_lo
156
145
}
146
+ } ;
157
147
158
- if !comment_after_assign. is_empty ( ) {
159
- let new_indent_str =
160
- & shape. block_indent ( 0 ) . to_string_with_newline ( context. config ) ;
161
- result. push_str ( new_indent_str) ;
162
- result. push_str ( comment_after_assign) ;
163
- result. push_str ( new_indent_str) ;
164
- }
148
+ if !comment_before_assign. is_empty ( ) {
149
+ let new_indent_str = & pat_shape
150
+ . block_indent ( 0 )
151
+ . to_string_with_newline ( context. config ) ;
152
+ result = format ! ( "{}{}{}" , comment_before_assign, new_indent_str, result) ;
165
153
}
166
154
167
155
// 1 = trailing semicolon;
168
156
let nested_shape = shape. sub_width ( 1 ) ?;
169
-
170
- result = rewrite_assign_rhs (
157
+ result = rewrite_assign_rhs_with_comments (
171
158
context,
172
159
result,
173
160
init,
174
- & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
175
161
nested_shape,
162
+ & RhsAssignKind :: Expr ( & init. kind , init. span ) ,
163
+ RhsTactics :: Default ,
164
+ mk_sp ( assign_hi, comment_end_pos) ,
165
+ true ,
176
166
) ?;
177
- // todo else
178
167
}
179
168
180
169
result. push ( ';' ) ;
0 commit comments