print argument name in arg mismatch if possible

This commit is contained in:
Michael Goulet 2022-12-17 20:59:23 +00:00
parent 984eab57f7
commit f034cb431d
5 changed files with 15 additions and 8 deletions

View file

@ -28,7 +28,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::visit::TypeVisitable;
use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor}; use rustc_middle::ty::{self, DefIdTree, IsSuggestable, Ty, TypeSuperVisitable, TypeVisitor};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::symbol::Ident; use rustc_span::symbol::{kw, Ident};
use rustc_span::{self, sym, Span}; use rustc_span::{self, sym, Span};
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext}; use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
@ -1141,6 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"()".to_string() "()".to_string()
} else if expected_ty.is_suggestable(tcx, false) { } else if expected_ty.is_suggestable(tcx, false) {
format!("/* {} */", expected_ty) 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 { } else {
"/* value */".to_string() "/* value */".to_string()
} }

View file

@ -94,8 +94,8 @@ LL | let closure = |x| x;
| ^^^ | ^^^
help: provide the argument help: provide the argument
| |
LL | closure(/* value */); LL | closure(/* x */);
| ~~~~~~~~~~~~~ | ~~~~~~~~~
error: aborting due to 6 previous errors error: aborting due to 6 previous errors

View file

@ -11,8 +11,8 @@ LL | let f = |x| x * 3;
| ^^^ | ^^^
help: provide the argument 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 error[E0057]: this function takes 1 argument but 2 arguments were supplied
--> $DIR/E0057.rs:5:13 --> $DIR/E0057.rs:5:13

View file

@ -11,8 +11,8 @@ LL | fn f<I>(i: I)
| ^ ---- | ^ ----
help: provide the argument help: provide the argument
| |
LL | f(&[f(/* value */)]); LL | f(&[f(/* i */)]);
| ~~~~~~~~~~~~~ | ~~~~~~~~~
error: aborting due to previous error error: aborting due to previous error

View file

@ -13,7 +13,7 @@ help: provide the argument
| |
LL ~ needlesArr.iter().fold(|x, y| { LL ~ needlesArr.iter().fold(|x, y| {
LL + LL +
LL ~ }, /* value */); LL ~ }, /* f */);
| |
error: aborting due to previous error error: aborting due to previous error