From 8d189ed2f1db856adc9745099d078d46fe54a087 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sat, 30 Nov 2019 18:59:51 +0100 Subject: [PATCH 1/6] Suggest calling method when first argument is `self` --- src/doc/rustc-guide | 2 +- src/librustc_resolve/build_reduced_graph.rs | 10 +++---- src/librustc_resolve/late.rs | 2 +- src/librustc_resolve/late/diagnostics.rs | 31 +++++++++++++++++++++ src/test/ui/self/suggest-self-2.rs | 22 +++++++++++++++ src/test/ui/self/suggest-self-2.stderr | 28 +++++++++++++++++++ 6 files changed, 88 insertions(+), 7 deletions(-) create mode 100644 src/test/ui/self/suggest-self-2.rs create mode 100644 src/test/ui/self/suggest-self-2.stderr diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 7c56708aab798..934380b7cfcea 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 7c56708aab7986ca390221e8e8902f7de7f9b076 +Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index fed4202d96103..c356a7e31b177 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -759,8 +759,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // These items live in both the type and value namespaces. ItemKind::Struct(ref vdata, _) => { // Define a name in the type namespace. - let def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Struct, def_id); + let item_def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Struct, item_def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. @@ -798,12 +798,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Union(ref vdata, _) => { - let def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Union, def_id); + let item_def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Union, item_def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. - self.insert_field_names_local(def_id, vdata); + self.insert_field_names_local(item_def_id, vdata); } ItemKind::Trait(..) => { diff --git a/src/librustc_resolve/late.rs b/src/librustc_resolve/late.rs index 898ab6ae32211..dd1bef0c297a9 100644 --- a/src/librustc_resolve/late.rs +++ b/src/librustc_resolve/late.rs @@ -345,7 +345,7 @@ struct DiagnosticMetadata { /// The current self item if inside an ADT (used for better errors). current_self_item: Option, - /// The current enclosing funciton (used for better errors). + /// The current enclosing function (used for better errors). current_function: Option, /// A list of labels as of yet unused. Labels will be removed from this map when diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 6fb5c2f2de31f..e40c6fa708888 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -259,6 +259,37 @@ impl<'a> LateResolutionVisitor<'a, '_> { } return (err, candidates); } + + // Check if the first argument is `self` and suggest calling a method. + let mut has_self_arg = false; + if let PathSource::Expr(parent) = source { + match &parent.map(|p| &p.kind) { + Some(ExprKind::Call(_, args)) if args.len() > 0 => { + let mut expr_kind = &args.first().unwrap().kind; + loop { + match expr_kind { + ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { + has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; + break; + }, + ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; } + _ => break, + } + } + } + _ => (), + } + }; + + if has_self_arg { + err.span_suggestion( + span, + &"try calling method instead of passing `self` as parameter", + format!("self.{}", path_str), + Applicability::MachineApplicable, + ); + return (err, candidates); + } } // Try Levenshtein algorithm. diff --git a/src/test/ui/self/suggest-self-2.rs b/src/test/ui/self/suggest-self-2.rs new file mode 100644 index 0000000000000..1926ebe4b8317 --- /dev/null +++ b/src/test/ui/self/suggest-self-2.rs @@ -0,0 +1,22 @@ +struct Foo {} + +impl Foo { + fn foo(&self) { + bar(self); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling method instead of passing `self` as parameter + + + bar(&self); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling method instead of passing `self` as parameter + + bar(); + //~^ ERROR cannot find function `bar` in this scope + + self.bar(); + //~^ ERROR no method named `bar` found for type + } +} + +fn main() {} diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr new file mode 100644 index 0000000000000..84dbaa9637898 --- /dev/null +++ b/src/test/ui/self/suggest-self-2.stderr @@ -0,0 +1,28 @@ +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:5:9 + | +LL | bar(self); + | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:10:9 + | +LL | bar(&self); + | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:14:9 + | +LL | bar(); + | ^^^ not found in this scope + +error[E0599]: no method named `bar` found for type `&Foo` in the current scope + --> $DIR/suggest-self-2.rs:17:14 + | +LL | self.bar(); + | ^^^ method not found in `&Foo` + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0425, E0599. +For more information about an error, try `rustc --explain E0425`. From 8e5b2c80d3f30c9d83a8e921e78e6c10e54c8319 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 9 Dec 2019 16:05:45 +0100 Subject: [PATCH 2/6] Add more detailed suggestion --- src/doc/rustc-guide | 2 +- src/librustc_resolve/build_reduced_graph.rs | 10 +++++----- src/librustc_resolve/late/diagnostics.rs | 6 +++--- src/test/ui/self/suggest-self-2.rs | 9 ++++++--- src/test/ui/self/suggest-self-2.stderr | 20 +++++++++++++------- 5 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/doc/rustc-guide b/src/doc/rustc-guide index 934380b7cfcea..7c56708aab798 160000 --- a/src/doc/rustc-guide +++ b/src/doc/rustc-guide @@ -1 +1 @@ -Subproject commit 934380b7cfceaaa4e1b9bb0de4a372f32725520b +Subproject commit 7c56708aab7986ca390221e8e8902f7de7f9b076 diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index c356a7e31b177..fed4202d96103 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -759,8 +759,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { // These items live in both the type and value namespaces. ItemKind::Struct(ref vdata, _) => { // Define a name in the type namespace. - let item_def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Struct, item_def_id); + let def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Struct, def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. @@ -798,12 +798,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> { } ItemKind::Union(ref vdata, _) => { - let item_def_id = self.r.definitions.local_def_id(item.id); - let res = Res::Def(DefKind::Union, item_def_id); + let def_id = self.r.definitions.local_def_id(item.id); + let res = Res::Def(DefKind::Union, def_id); self.r.define(parent, ident, TypeNS, (res, vis, sp, expansion)); // Record field names for error reporting. - self.insert_field_names_local(item_def_id, vdata); + self.insert_field_names_local(def_id, vdata); } ItemKind::Trait(..) => { diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index e40c6fa708888..cc6fbf840a454 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -265,14 +265,14 @@ impl<'a> LateResolutionVisitor<'a, '_> { if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { - let mut expr_kind = &args.first().unwrap().kind; + let mut expr_kind = &args[0].kind; loop { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; break; }, - ExprKind::AddrOf(_, _, expr) => { expr_kind = &expr.kind; } + ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, _ => break, } } @@ -284,7 +284,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { if has_self_arg { err.span_suggestion( span, - &"try calling method instead of passing `self` as parameter", + &format!("try calling `{}` as a method", ident), format!("self.{}", path_str), Applicability::MachineApplicable, ); diff --git a/src/test/ui/self/suggest-self-2.rs b/src/test/ui/self/suggest-self-2.rs index 1926ebe4b8317..d6bf543352701 100644 --- a/src/test/ui/self/suggest-self-2.rs +++ b/src/test/ui/self/suggest-self-2.rs @@ -4,12 +4,15 @@ impl Foo { fn foo(&self) { bar(self); //~^ ERROR cannot find function `bar` in this scope - //~| HELP try calling method instead of passing `self` as parameter + //~| HELP try calling `bar` as a method + bar(&&self, 102); + //~^ ERROR cannot find function `bar` in this scope + //~| HELP try calling `bar` as a method - bar(&self); + bar(&mut self, 102, &"str"); //~^ ERROR cannot find function `bar` in this scope - //~| HELP try calling method instead of passing `self` as parameter + //~| HELP try calling `bar` as a method bar(); //~^ ERROR cannot find function `bar` in this scope diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index 84dbaa9637898..ba71498fae656 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,27 +2,33 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar` error[E0425]: cannot find function `bar` in this scope - --> $DIR/suggest-self-2.rs:10:9 + --> $DIR/suggest-self-2.rs:9:9 | -LL | bar(&self); - | ^^^ help: try calling method instead of passing `self` as parameter: `self.bar` +LL | bar(&&self, 102); + | ^^^ help: try calling `bar` as a method: `self.bar` error[E0425]: cannot find function `bar` in this scope - --> $DIR/suggest-self-2.rs:14:9 + --> $DIR/suggest-self-2.rs:13:9 + | +LL | bar(&mut self, 102, &"str"); + | ^^^ help: try calling `bar` as a method: `self.bar` + +error[E0425]: cannot find function `bar` in this scope + --> $DIR/suggest-self-2.rs:17:9 | LL | bar(); | ^^^ not found in this scope error[E0599]: no method named `bar` found for type `&Foo` in the current scope - --> $DIR/suggest-self-2.rs:17:14 + --> $DIR/suggest-self-2.rs:20:14 | LL | self.bar(); | ^^^ method not found in `&Foo` -error: aborting due to 4 previous errors +error: aborting due to 5 previous errors Some errors have detailed explanations: E0425, E0599. For more information about an error, try `rustc --explain E0425`. From 091853946bc0f3e9138875bfe1952e857e601896 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sat, 21 Dec 2019 19:13:12 +0100 Subject: [PATCH 3/6] Add arguments to suggestion method call --- src/librustc_resolve/late/diagnostics.rs | 17 ++++++++++++++++- src/test/ui/self/suggest-self-2.stderr | 6 +++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index cc6fbf840a454..43626d87d71d5 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -262,6 +262,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { // Check if the first argument is `self` and suggest calling a method. let mut has_self_arg = false; + let mut args_span = None; if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { @@ -270,6 +271,13 @@ impl<'a> LateResolutionVisitor<'a, '_> { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; + if args.len() > 1 { + args_span = Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + parent.unwrap().span.ctxt(), + )); + } break; }, ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, @@ -282,10 +290,17 @@ impl<'a> LateResolutionVisitor<'a, '_> { }; if has_self_arg { + let mut args_snippet: String = String::from(""); + if let Some(args_span) = args_span { + if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { + args_snippet = snippet; + } + } + err.span_suggestion( span, &format!("try calling `{}` as a method", ident), - format!("self.{}", path_str), + format!("self.{}({})", path_str, args_snippet), Applicability::MachineApplicable, ); return (err, candidates); diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index ba71498fae656..6148012ac0d92 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,19 +2,19 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar()` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:9:9 | LL | bar(&&self, 102); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar(102)` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:13:9 | LL | bar(&mut self, 102, &"str"); - | ^^^ help: try calling `bar` as a method: `self.bar` + | ^^^ help: try calling `bar` as a method: `self.bar(102, &"str")` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:17:9 From 7353afdfd9b992a0254b8c23592e91cde792d514 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Sun, 22 Dec 2019 22:48:45 +0100 Subject: [PATCH 4/6] Extend suggestion span to whole method call --- src/librustc_resolve/late/diagnostics.rs | 26 ++++++++++++++---------- src/test/ui/self/suggest-self-2.stderr | 12 ++++++++--- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 43626d87d71d5..a1cbcac1a9a76 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -261,8 +261,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } // Check if the first argument is `self` and suggest calling a method. - let mut has_self_arg = false; - let mut args_span = None; + let mut has_self_arg = None; if let PathSource::Expr(parent) = source { match &parent.map(|p| &p.kind) { Some(ExprKind::Call(_, args)) if args.len() > 0 => { @@ -270,13 +269,18 @@ impl<'a> LateResolutionVisitor<'a, '_> { loop { match expr_kind { ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { - has_self_arg = arg_name.segments[0].ident.name == kw::SelfLower; - if args.len() > 1 { - args_span = Some(Span::new( - args[1].span.lo(), - args.last().unwrap().span.hi(), - parent.unwrap().span.ctxt(), - )); + if arg_name.segments[0].ident.name == kw::SelfLower { + let call_span = parent.unwrap().span; + let args_span = if args.len() > 1 { + Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + call_span.ctxt(), + )) + } else { + None + }; + has_self_arg = Some((call_span, args_span)); } break; }, @@ -289,7 +293,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } }; - if has_self_arg { + if let Some((call_span, args_span)) = has_self_arg { let mut args_snippet: String = String::from(""); if let Some(args_span) = args_span { if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { @@ -298,7 +302,7 @@ impl<'a> LateResolutionVisitor<'a, '_> { } err.span_suggestion( - span, + call_span, &format!("try calling `{}` as a method", ident), format!("self.{}({})", path_str, args_snippet), Applicability::MachineApplicable, diff --git a/src/test/ui/self/suggest-self-2.stderr b/src/test/ui/self/suggest-self-2.stderr index 6148012ac0d92..452c31275153a 100644 --- a/src/test/ui/self/suggest-self-2.stderr +++ b/src/test/ui/self/suggest-self-2.stderr @@ -2,19 +2,25 @@ error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:5:9 | LL | bar(self); - | ^^^ help: try calling `bar` as a method: `self.bar()` + | ^^^------ + | | + | help: try calling `bar` as a method: `self.bar()` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:9:9 | LL | bar(&&self, 102); - | ^^^ help: try calling `bar` as a method: `self.bar(102)` + | ^^^------------- + | | + | help: try calling `bar` as a method: `self.bar(102)` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:13:9 | LL | bar(&mut self, 102, &"str"); - | ^^^ help: try calling `bar` as a method: `self.bar(102, &"str")` + | ^^^------------------------ + | | + | help: try calling `bar` as a method: `self.bar(102, &"str")` error[E0425]: cannot find function `bar` in this scope --> $DIR/suggest-self-2.rs:17:9 From 2168c0b9791d55361177efa3bb7e79f7b944a423 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 23 Dec 2019 11:56:34 +0100 Subject: [PATCH 5/6] Extract checking for self arg to separate method --- src/librustc_resolve/late/diagnostics.rs | 75 +++++++++++++----------- 1 file changed, 40 insertions(+), 35 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index a1cbcac1a9a76..904a4125f2f72 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -260,41 +260,9 @@ impl<'a> LateResolutionVisitor<'a, '_> { return (err, candidates); } - // Check if the first argument is `self` and suggest calling a method. - let mut has_self_arg = None; - if let PathSource::Expr(parent) = source { - match &parent.map(|p| &p.kind) { - Some(ExprKind::Call(_, args)) if args.len() > 0 => { - let mut expr_kind = &args[0].kind; - loop { - match expr_kind { - ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { - if arg_name.segments[0].ident.name == kw::SelfLower { - let call_span = parent.unwrap().span; - let args_span = if args.len() > 1 { - Some(Span::new( - args[1].span.lo(), - args.last().unwrap().span.hi(), - call_span.ctxt(), - )) - } else { - None - }; - has_self_arg = Some((call_span, args_span)); - } - break; - }, - ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, - _ => break, - } - } - } - _ => (), - } - }; - - if let Some((call_span, args_span)) = has_self_arg { - let mut args_snippet: String = String::from(""); + // If the first argument in call is `self` suggest calling a method. + if let Some((call_span, args_span)) = self.call_has_self_arg(source) { + let mut args_snippet = String::new(); if let Some(args_span) = args_span { if let Ok(snippet) = self.r.session.source_map().span_to_snippet(args_span) { args_snippet = snippet; @@ -348,6 +316,43 @@ impl<'a> LateResolutionVisitor<'a, '_> { (err, candidates) } + /// Check if the source is call expression and the first argument is `self`. If true, + /// return the span of whole call and the span for all arguments expect the first one (`self`). + fn call_has_self_arg(&self, source: PathSource<'_>) -> Option<(Span, Option)> { + let mut has_self_arg = None; + if let PathSource::Expr(parent) = source { + match &parent.map(|p| &p.kind) { + Some(ExprKind::Call(_, args)) if args.len() > 0 => { + let mut expr_kind = &args[0].kind; + loop { + match expr_kind { + ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => { + if arg_name.segments[0].ident.name == kw::SelfLower { + let call_span = parent.unwrap().span; + let tail_args_span = if args.len() > 1 { + Some(Span::new( + args[1].span.lo(), + args.last().unwrap().span.hi(), + call_span.ctxt(), + )) + } else { + None + }; + has_self_arg = Some((call_span, tail_args_span)); + } + break; + } + ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind, + _ => break, + } + } + } + _ => (), + } + }; + return has_self_arg; + } + fn followed_by_brace(&self, span: Span) -> (bool, Option<(Span, String)>) { // HACK(estebank): find a better way to figure out that this was a // parser issue where a struct literal is being used on an expression From 7b91ef8837cb5e926418aeb4a675313ba928c877 Mon Sep 17 00:00:00 2001 From: Janusz Marcinkiewicz Date: Mon, 23 Dec 2019 15:55:35 +0100 Subject: [PATCH 6/6] Simplify match expr --- src/librustc_resolve/late/diagnostics.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/late/diagnostics.rs b/src/librustc_resolve/late/diagnostics.rs index 904a4125f2f72..e3895e18d668d 100644 --- a/src/librustc_resolve/late/diagnostics.rs +++ b/src/librustc_resolve/late/diagnostics.rs @@ -321,8 +321,8 @@ impl<'a> LateResolutionVisitor<'a, '_> { fn call_has_self_arg(&self, source: PathSource<'_>) -> Option<(Span, Option)> { let mut has_self_arg = None; if let PathSource::Expr(parent) = source { - match &parent.map(|p| &p.kind) { - Some(ExprKind::Call(_, args)) if args.len() > 0 => { + match &parent?.kind { + ExprKind::Call(_, args) if args.len() > 0 => { let mut expr_kind = &args[0].kind; loop { match expr_kind {