From 37d62fbf9e5bd2010896a28d6b363bd85cbecb33 Mon Sep 17 00:00:00 2001 From: Lukas Markeffsky <@> Date: Sat, 10 Jun 2023 19:23:40 +0200 Subject: [PATCH] don't remove args for function calls coming from macro expansions --- compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 +++- .../ui/argument-suggestions/extra_arguments.stderr | 13 +------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 8e49aa3e656..15bb67db6e9 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -929,7 +929,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; labels.push((provided_span, format!("unexpected argument{provided_ty_name}"))); let mut span = provided_span; - if span.can_be_used_for_suggestions() { + if span.can_be_used_for_suggestions() + && error_span.can_be_used_for_suggestions() + { if arg_idx.index() > 0 && let Some((_, prev)) = provided_arg_tys .get(ProvidedIdx::from_usize(arg_idx.index() - 1) diff --git a/tests/ui/argument-suggestions/extra_arguments.stderr b/tests/ui/argument-suggestions/extra_arguments.stderr index 1016c7ba438..bd32780c88f 100644 --- a/tests/ui/argument-suggestions/extra_arguments.stderr +++ b/tests/ui/argument-suggestions/extra_arguments.stderr @@ -258,7 +258,6 @@ LL | foo!(1, ~); | ---------- | | | | | unexpected argument of type `{integer}` - | | help: remove the extra argument | in this macro invocation | note: function defined here @@ -272,9 +271,7 @@ error[E0061]: this function takes 0 arguments but 2 arguments were supplied --> $DIR/extra_arguments.rs:14:9 | LL | empty(1, $y); - | ^^^^^ ----- help: remove the extra argument - | | - | unexpected argument of type `{integer}` + | ^^^^^ - unexpected argument of type `{integer}` ... LL | foo!(~, 1); | ---------- @@ -308,14 +305,6 @@ note: function defined here LL | fn empty() {} | ^^^^^ = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) -help: remove the extra arguments - | -LL ~ empty($x, $y; -LL | }; - ... -LL | foo!(~, 1); -LL ~ foo!(, 1); - | error[E0061]: this function takes 1 argument but 2 arguments were supplied --> $DIR/extra_arguments.rs:53:3