about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibsG <thibsg@pm.me>2021-10-01 17:29:37 +0200
committerThibsG <thibsg@pm.me>2021-11-20 09:40:11 +0100
commitabaaf744fdbe8106bc82ceaa34e8499d5436fc3c (patch)
tree3397beefbff14efd6eacfcbe8caf8623f6586351
parent268ef407a65ba07601f8cd70bf40537d76376aa9 (diff)
downloadrust-abaaf744fdbe8106bc82ceaa34e8499d5436fc3c.tar.gz
rust-abaaf744fdbe8106bc82ceaa34e8499d5436fc3c.zip
Add some notes about `MethodCall` cases
-rw-r--r--clippy_lints/src/methods/search_is_some.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/clippy_lints/src/methods/search_is_some.rs b/clippy_lints/src/methods/search_is_some.rs
index 4f8517b946a..d08abc5b3de 100644
--- a/clippy_lints/src/methods/search_is_some.rs
+++ b/clippy_lints/src/methods/search_is_some.rs
@@ -221,7 +221,7 @@ struct DerefDelegate<'a, 'tcx> {
 
 impl DerefDelegate<'_, 'tcx> {
     pub fn finish(&mut self) -> String {
-        let end_span = Span::new(self.next_pos, self.closure_span.hi(), self.closure_span.ctxt());
+        let end_span = Span::new(self.next_pos, self.closure_span.hi(), self.closure_span.ctxt(), None);
         let end_snip = snippet_with_applicability(self.cx, end_span, "..", &mut self.applicability);
         format!("{}{}", self.suggestion_start, end_snip)
     }
@@ -255,7 +255,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 = Span::new(self.next_pos, span.lo(), span.ctxt());
+            let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None);
             let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
 
             if cmt.place.projections.is_empty() {
@@ -263,8 +263,14 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
                 // i.e.: suggest `&x` instead of `x`
                 self.suggestion_start.push_str(&format!("{}&{}", start_snip, ident_str));
             } else {
-                // cases where a parent call is using the item
+                // cases where a parent `Call` or `MethodCall` is using the item
                 // i.e.: suggest `.contains(&x)` for `.find(|x| [1, 2, 3].contains(x)).is_none()`
+                //
+                // Note about method calls:
+                // - compiler automatically dereference references if the target type is a reference (works also for
+                //   function call)
+                // - `self` arguments in the case of `x.is_something()` are also automatically (de)referenced, and
+                //   no projection should be suggested
                 if let Some(parent_expr) = get_parent_expr_for_hir(self.cx, cmt.hir_id) {
                     if let ExprKind::Call(_, call_args) | ExprKind::MethodCall(_, _, call_args, _) = parent_expr.kind {
                         let expr = self.cx.tcx.hir().expect_expr(cmt.hir_id);
@@ -316,7 +322,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
                         // so the span is set-up again to get more code, using `span.hi()` (i.e.: `foo[x]`)
                         // instead of `span.lo()` (i.e.: `foo`)
                         ProjectionKind::Index => {
-                            let start_span = Span::new(self.next_pos, span.hi(), span.ctxt());
+                            let start_span = Span::new(self.next_pos, span.hi(), span.ctxt(), None);
                             start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
                             replacement_str.clear();
                             projections_handled = true;