@@ -166,7 +166,6 @@ fn get_closure_suggestion<'tcx>(
166
166
closure_span : search_arg. span ,
167
167
next_pos : search_arg. span . lo ( ) ,
168
168
suggestion_start : String :: new ( ) ,
169
- suggestion_end : String :: new ( ) ,
170
169
applicability : Applicability :: MachineApplicable ,
171
170
} ;
172
171
@@ -179,7 +178,7 @@ fn get_closure_suggestion<'tcx>(
179
178
if visitor. suggestion_start . is_empty ( ) {
180
179
None
181
180
} else {
182
- Some ( format ! ( "{}{}" , visitor. suggestion_start , visitor . suggestion_end ) )
181
+ Some ( visitor. finish ( ) )
183
182
}
184
183
}
185
184
@@ -188,10 +187,17 @@ struct DerefDelegate<'a, 'tcx> {
188
187
closure_span : Span ,
189
188
next_pos : BytePos ,
190
189
suggestion_start : String ,
191
- suggestion_end : String ,
192
190
applicability : Applicability ,
193
191
}
194
192
193
+ impl DerefDelegate < ' _ , ' tcx > {
194
+ pub fn finish ( & mut self ) -> String {
195
+ let end_span = Span :: new ( self . next_pos , self . closure_span . hi ( ) , self . closure_span . ctxt ( ) ) ;
196
+ let end_snip = snippet_with_applicability ( self . cx , end_span, ".." , & mut self . applicability ) ;
197
+ format ! ( "{}{}" , self . suggestion_start, end_snip)
198
+ }
199
+ }
200
+
195
201
impl < ' tcx > Delegate < ' tcx > for DerefDelegate < ' _ , ' tcx > {
196
202
fn consume ( & mut self , _: & PlaceWithHirId < ' tcx > , _: HirId ) { }
197
203
@@ -202,8 +208,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
202
208
let span = map. span ( cmt. hir_id ) ;
203
209
let start_span = Span :: new ( self . next_pos , span. lo ( ) , span. ctxt ( ) ) ;
204
210
let start_snip = snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
205
- let end_span = Span :: new ( span. hi ( ) , self . closure_span . hi ( ) , span. ctxt ( ) ) ;
206
- let end_snip = snippet_with_applicability ( self . cx , end_span, ".." , & mut self . applicability ) ;
207
211
208
212
if cmt. place . projections . is_empty ( ) {
209
213
// handle item without any projection, that needs an explicit borrowing
@@ -225,7 +229,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
225
229
snippet_with_applicability ( self . cx , start_span, ".." , & mut self . applicability ) ;
226
230
227
231
self . suggestion_start . push_str ( & format ! ( "{}&{}" , start_snip, ident_str) ) ;
228
- self . suggestion_end = end_snip. to_string ( ) ;
229
232
self . next_pos = span. hi ( ) ;
230
233
} else {
231
234
self . applicability = Applicability :: Unspecified ;
@@ -258,7 +261,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
258
261
259
262
self . suggestion_start
260
263
. push_str ( & format ! ( "{}{}" , start_snip, replacement_str) ) ;
261
- self . suggestion_end = end_snip. to_string ( ) ;
262
264
}
263
265
self . next_pos = span. hi ( ) ;
264
266
}
0 commit comments