Skip to content

Commit 9ab4b67

Browse files
committed
Simplifying next_pos init
1 parent e24aba2 commit 9ab4b67

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

clippy_lints/src/methods/search_is_some.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ fn get_closure_suggestion<'tcx>(
164164
let mut visitor = DerefDelegate {
165165
cx,
166166
closure_span: search_arg.span,
167-
next_pos: None,
167+
next_pos: search_arg.span.lo(),
168168
suggestion_start: String::new(),
169169
suggestion_end: String::new(),
170170
applicability: Applicability::MachineApplicable,
@@ -186,7 +186,7 @@ fn get_closure_suggestion<'tcx>(
186186
struct DerefDelegate<'a, 'tcx> {
187187
cx: &'a LateContext<'tcx>,
188188
closure_span: Span,
189-
next_pos: Option<BytePos>,
189+
next_pos: BytePos,
190190
suggestion_start: String,
191191
suggestion_end: String,
192192
applicability: Applicability,
@@ -200,11 +200,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
200200
let map = self.cx.tcx.hir();
201201
let ident_str = map.name(id).to_string();
202202
let span = map.span(cmt.hir_id);
203-
let start_span = if let Some(next_pos) = self.next_pos {
204-
Span::new(next_pos, span.lo(), span.ctxt())
205-
} else {
206-
self.closure_span.until(span)
207-
};
203+
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
208204
let start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
209205
let end_span = Span::new(span.hi(), self.closure_span.hi(), span.ctxt());
210206
let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
@@ -224,17 +220,13 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
224220
for arg in &args_to_handle {
225221
let arg_ty_kind = self.cx.typeck_results().expr_ty(arg).kind();
226222
if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
227-
let start_span = if let Some(next_pos) = self.next_pos {
228-
Span::new(next_pos, span.lo(), span.ctxt())
229-
} else {
230-
self.closure_span.until(span)
231-
};
223+
let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
232224
let start_snip =
233225
snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
234226

235227
self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
236228
self.suggestion_end = end_snip.to_string();
237-
self.next_pos = Some(span.hi());
229+
self.next_pos = span.hi();
238230
} else {
239231
self.applicability = Applicability::Unspecified;
240232
}
@@ -268,7 +260,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
268260
.push_str(&format!("{}{}", start_snip, replacement_str));
269261
self.suggestion_end = end_snip.to_string();
270262
}
271-
self.next_pos = Some(span.hi());
263+
self.next_pos = span.hi();
272264
}
273265
}
274266

0 commit comments

Comments
 (0)