about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <thibsg@pm.me>2021-09-07 11:18:27 +0200
committerThibsG <thibsg@pm.me>2021-11-20 09:40:11 +0100
commit9ab4b673eb41cca04a626797bb130bda4a14bd1b (patch)
tree4b42c90de223269c38ab67d6a1a70465d551e5bf
parente24aba2c1a8663c2ddebdae740689f8a7bdcadb7 (diff)
downloadrust-9ab4b673eb41cca04a626797bb130bda4a14bd1b.tar.gz
rust-9ab4b673eb41cca04a626797bb130bda4a14bd1b.zip
Simplifying `next_pos` init
-rw-r--r--clippy_lints/src/methods/search_is_some.rs20
1 files changed, 6 insertions, 14 deletions
diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs
index ec09bfd743d..b38b8e44f1c 100644
--- a/clippy_lints/src/methods/search_is_some.rs
+++ b/clippy_lints/src/methods/search_is_some.rs
@@ -164,7 +164,7 @@ fn get_closure_suggestion<'tcx>(
     let mut visitor = DerefDelegate {
         cx,
         closure_span: search_arg.span,
-        next_pos: None,
+        next_pos: search_arg.span.lo(),
         suggestion_start: String::new(),
         suggestion_end: String::new(),
         applicability: Applicability::MachineApplicable,
@@ -186,7 +186,7 @@ fn get_closure_suggestion<'tcx>(
 struct DerefDelegate<'a, 'tcx> {
     cx: &'a LateContext<'tcx>,
     closure_span: Span,
-    next_pos: Option<BytePos>,
+    next_pos: BytePos,
     suggestion_start: String,
     suggestion_end: String,
     applicability: Applicability,
@@ -200,11 +200,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
             let map = self.cx.tcx.hir();
             let ident_str = map.name(id).to_string();
             let span = map.span(cmt.hir_id);
-            let start_span = if let Some(next_pos) = self.next_pos {
-                Span::new(next_pos, span.lo(), span.ctxt())
-            } else {
-                self.closure_span.until(span)
-            };
+            let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
             let start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
             let end_span = Span::new(span.hi(), self.closure_span.hi(), span.ctxt());
             let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
@@ -224,17 +220,13 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
                             for arg in &args_to_handle {
                                 let arg_ty_kind = self.cx.typeck_results().expr_ty(arg).kind();
                                 if matches!(arg_ty_kind, ty::Ref(_, _, Mutability::Not)) {
-                                    let start_span = if let Some(next_pos) = self.next_pos {
-                                        Span::new(next_pos, span.lo(), span.ctxt())
-                                    } else {
-                                        self.closure_span.until(span)
-                                    };
+                                    let start_span = Span::new(self.next_pos, span.lo(), span.ctxt());
                                     let start_snip =
                                         snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
 
                                     self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
                                     self.suggestion_end = end_snip.to_string();
-                                    self.next_pos = Some(span.hi());
+                                    self.next_pos = span.hi();
                                 } else {
                                     self.applicability = Applicability::Unspecified;
                                 }
@@ -268,7 +260,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
                     .push_str(&format!("{}{}", start_snip, replacement_str));
                 self.suggestion_end = end_snip.to_string();
             }
-            self.next_pos = Some(span.hi());
+            self.next_pos = span.hi();
         }
     }