@@ -112,56 +112,26 @@ impl Rewrite for ast::Local {
112
112
113
113
result. push_str ( & infix) ;
114
114
115
- if let Some ( ( init , _els ) ) = self . kind . init_else_opt ( ) {
115
+ if let Some ( expr ) = self . kind . init ( ) {
116
116
let base_span = if let Some ( ref ty) = self . ty {
117
117
mk_sp ( ty. span . hi ( ) , self . span . hi ( ) )
118
118
} else {
119
119
mk_sp ( self . pat . span . hi ( ) , self . span . hi ( ) )
120
120
} ;
121
121
122
- let offset = context. snippet ( base_span) . find_uncommented ( "=" ) ?;
123
- let base_span_lo = base_span. lo ( ) ;
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 = context. snippet ( mk_sp ( comment_start_pos, assign_lo) ) . trim ( ) ;
132
-
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 {
142
- rhs_span_lo
143
- } else {
144
- attr_span_lo
145
- }
146
- } ;
147
-
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) ;
153
- }
122
+ let comment_lo = context. snippet_provider . span_after ( base_span, "=" ) ;
123
+ let comment_span = mk_sp ( comment_lo, expr. span . lo ( ) ) ;
154
124
155
125
// 1 = trailing semicolon;
156
126
let nested_shape = shape. sub_width ( 1 ) ?;
157
127
result = rewrite_assign_rhs_with_comments (
158
128
context,
159
129
result,
160
- init ,
130
+ expr ,
161
131
nested_shape,
162
- & RhsAssignKind :: Expr ( & init . kind , init . span ) ,
132
+ & RhsAssignKind :: Expr ( & expr . kind , expr . span ) ,
163
133
RhsTactics :: Default ,
164
- mk_sp ( assign_hi , comment_end_pos ) ,
134
+ comment_span ,
165
135
true ,
166
136
) ?;
167
137
}
0 commit comments