Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

print argument name in arg mismatch if possible #105842

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use rustc_middle::ty::adjustment::AllowTwoPhase;
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};

Expand Down Expand Up @@ -1141,6 +1141,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
"()".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()
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/argument-suggestions/basic.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0057.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/higher-rank-trait-bounds/issue-58451.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ LL | fn f<I>(i: I)
| ^ ----
help: provide the argument
|
LL | f(&[f(/* value */)]);
| ~~~~~~~~~~~~~
LL | f(&[f(/* i */)]);
| ~~~~~~~~~

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-3044.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down