From f034cb431d88a89984eb75bdea120e34fabfc798 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 17 Dec 2022 20:59:23 +0000 Subject: [PATCH] print argument name in arg mismatch if possible --- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 9 ++++++++- src/test/ui/argument-suggestions/basic.stderr | 4 ++-- src/test/ui/error-codes/E0057.stderr | 4 ++-- src/test/ui/higher-rank-trait-bounds/issue-58451.stderr | 4 ++-- src/test/ui/issues/issue-3044.stderr | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 8e520e563ff..829697c4b9a 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -28,7 +28,7 @@ use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor}; use rustc_session::Session; -use rustc_span::symbol::Ident; +use rustc_span::symbol::{kw, Ident}; use rustc_span::{self, sym, Span}; use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext}; @@ -1141,6 +1141,13 @@ enum SuggestionText { "()".to_string() } else if expected_ty.is_suggestable(tcx, false) { format!("/* {} */", expected_ty) + } else if let Some(fn_def_id) = fn_def_id + && self.tcx.def_kind(fn_def_id).is_fn_like() + && let self_implicit = matches!(call_expr.kind, hir::ExprKind::MethodCall(..)) as usize + && let Some(arg) = self.tcx.fn_arg_names(fn_def_id).get(expected_idx.as_usize() + self_implicit) + && arg.name != kw::SelfLower + { + format!("/* {} */", arg.name) } else { "/* value */".to_string() } diff --git a/src/test/ui/argument-suggestions/basic.stderr b/src/test/ui/argument-suggestions/basic.stderr index b118ce1bd0e..062b3768858 100644 --- a/src/test/ui/argument-suggestions/basic.stderr +++ b/src/test/ui/argument-suggestions/basic.stderr @@ -94,8 +94,8 @@ LL | let closure = |x| x; | ^^^ help: provide the argument | -LL | closure(/* value */); - | ~~~~~~~~~~~~~ +LL | closure(/* x */); + | ~~~~~~~~~ error: aborting due to 6 previous errors diff --git a/src/test/ui/error-codes/E0057.stderr b/src/test/ui/error-codes/E0057.stderr index bea226f09dc..163737895fe 100644 --- a/src/test/ui/error-codes/E0057.stderr +++ b/src/test/ui/error-codes/E0057.stderr @@ -11,8 +11,8 @@ LL | let f = |x| x * 3; | ^^^ help: provide the argument | -LL | let a = f(/* value */); - | ~~~~~~~~~~~~~ +LL | let a = f(/* x */); + | ~~~~~~~~~ error[E0057]: this function takes 1 argument but 2 arguments were supplied --> $DIR/E0057.rs:5:13 diff --git a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr index 09e25f4dc96..0f051be2128 100644 --- a/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr +++ b/src/test/ui/higher-rank-trait-bounds/issue-58451.stderr @@ -11,8 +11,8 @@ LL | fn f(i: I) | ^ ---- help: provide the argument | -LL | f(&[f(/* value */)]); - | ~~~~~~~~~~~~~ +LL | f(&[f(/* i */)]); + | ~~~~~~~~~ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-3044.stderr b/src/test/ui/issues/issue-3044.stderr index 2b142f688ec..1232b83c391 100644 --- a/src/test/ui/issues/issue-3044.stderr +++ b/src/test/ui/issues/issue-3044.stderr @@ -13,7 +13,7 @@ help: provide the argument | LL ~ needlesArr.iter().fold(|x, y| { LL + -LL ~ }, /* value */); +LL ~ }, /* f */); | error: aborting due to previous error