Skip to content

Commit d0dd797

Browse files
committed
Build end of suggestion only once at the end of the process
1 parent 9ab4b67 commit d0dd797

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

clippy_lints/src/methods/search_is_some.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ fn get_closure_suggestion<'tcx>(
166166
closure_span: search_arg.span,
167167
next_pos: search_arg.span.lo(),
168168
suggestion_start: String::new(),
169-
suggestion_end: String::new(),
170169
applicability: Applicability::MachineApplicable,
171170
};
172171

@@ -179,7 +178,7 @@ fn get_closure_suggestion<'tcx>(
179178
if visitor.suggestion_start.is_empty() {
180179
None
181180
} else {
182-
Some(format!("{}{}", visitor.suggestion_start, visitor.suggestion_end))
181+
Some(visitor.finish())
183182
}
184183
}
185184

@@ -188,10 +187,17 @@ struct DerefDelegate<'a, 'tcx> {
188187
closure_span: Span,
189188
next_pos: BytePos,
190189
suggestion_start: String,
191-
suggestion_end: String,
192190
applicability: Applicability,
193191
}
194192

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+
195201
impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
196202
fn consume(&mut self, _: &PlaceWithHirId<'tcx>, _: HirId) {}
197203

@@ -202,8 +208,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
202208
let span = map.span(cmt.hir_id);
203209
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
204210
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);
207211

208212
if cmt.place.projections.is_empty() {
209213
// handle item without any projection, that needs an explicit borrowing
@@ -225,7 +229,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
225229
snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
226230

227231
self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
228-
self.suggestion_end = end_snip.to_string();
229232
self.next_pos = span.hi();
230233
} else {
231234
self.applicability = Applicability::Unspecified;
@@ -258,7 +261,6 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
258261

259262
self.suggestion_start
260263
.push_str(&format!("{}{}", start_snip, replacement_str));
261-
self.suggestion_end = end_snip.to_string();
262264
}
263265
self.next_pos = span.hi();
264266
}

0 commit comments

Comments
 (0)