From 3efa5b4b83b3fe72570d50ce73b8382875a4bdfa Mon Sep 17 00:00:00 2001 From: jam1garner <8260240+jam1garner@users.noreply.github.com> Date: Mon, 14 Jun 2021 22:43:19 -0400 Subject: [PATCH] Emit additional arguments in `future_prelude_collision` lint --- compiler/rustc_typeck/src/check/expr.rs | 2 +- compiler/rustc_typeck/src/check/method/mod.rs | 6 ++++-- .../src/check/method/prelude2021.rs | 17 ++++++++++++++++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index e6a2c5d5d14..28ab6b15133 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -941,7 +941,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // no need to check for bot/err -- callee does that let rcvr_t = self.structurally_resolved_type(args[0].span, rcvr_t); - let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr) { + let method = match self.lookup_method(rcvr_t, segment, span, expr, rcvr, args) { Ok(method) => { // We could add a "consider `foo::`" suggestion here, but I wasn't able to // trigger this codepath causing `structuraly_resolved_type` to emit an error. diff --git a/compiler/rustc_typeck/src/check/method/mod.rs b/compiler/rustc_typeck/src/check/method/mod.rs index e956637dec1..be6bc625d89 100644 --- a/compiler/rustc_typeck/src/check/method/mod.rs +++ b/compiler/rustc_typeck/src/check/method/mod.rs @@ -174,7 +174,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// /// # Arguments /// - /// Given a method call like `foo.bar::(...)`: + /// Given a method call like `foo.bar::(a, b + 1, ...)`: /// /// * `self`: the surrounding `FnCtxt` (!) /// * `self_ty`: the (unadjusted) type of the self expression (`foo`) @@ -182,6 +182,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { /// * `span`: the span for the method call /// * `call_expr`: the complete method call: (`foo.bar::(...)`) /// * `self_expr`: the self expression (`foo`) + /// * `args`: the expressions of the arguments (`a, b + 1, ...`) #[instrument(level = "debug", skip(self, call_expr, self_expr))] pub fn lookup_method( &self, @@ -190,6 +191,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { span: Span, call_expr: &'tcx hir::Expr<'tcx>, self_expr: &'tcx hir::Expr<'tcx>, + args: &'tcx [hir::Expr<'tcx>], ) -> Result, MethodError<'tcx>> { debug!( "lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})", @@ -199,7 +201,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let pick = self.lookup_probe(span, segment.ident, self_ty, call_expr, ProbeScope::TraitsInScope)?; - self.lint_dot_call_from_2018(self_ty, segment, span, call_expr, self_expr, &pick); + self.lint_dot_call_from_2018(self_ty, segment, span, call_expr, self_expr, &pick, args); for import_id in &pick.import_ids { debug!("used_trait_import: {:?}", import_id); diff --git a/compiler/rustc_typeck/src/check/method/prelude2021.rs b/compiler/rustc_typeck/src/check/method/prelude2021.rs index b141a4f6f89..b7e41525bde 100644 --- a/compiler/rustc_typeck/src/check/method/prelude2021.rs +++ b/compiler/rustc_typeck/src/check/method/prelude2021.rs @@ -20,6 +20,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { call_expr: &'tcx hir::Expr<'tcx>, self_expr: &'tcx hir::Expr<'tcx>, pick: &Pick<'tcx>, + args: &'tcx [hir::Expr<'tcx>], ) { debug!( "lookup(method_name={}, self_ty={:?}, call_expr={:?}, self_expr={:?})", @@ -75,10 +76,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } else { format!("{}{}{}", autoref, derefs, self_expr) }; + let args = args + .iter() + .skip(1) + .map(|arg| { + format!( + ", {}", + self.sess().source_map().span_to_snippet(arg.span).unwrap() + ) + }) + .collect::(); + lint.span_suggestion( sp, "disambiguate the associated function", - format!("{}::{}({})", trait_name, segment.ident.name, self_adjusted,), + format!( + "{}::{}({}{})", + trait_name, segment.ident.name, self_adjusted, args + ), Applicability::MachineApplicable, ); } else {