Skip to content

Commit b54ba21

Browse files
committed
Avoid incorrect argument suggestions in macros
1 parent d692d37 commit b54ba21

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
3131
use rustc_middle::ty::{self, IsSuggestable, Ty};
3232
use rustc_session::Session;
3333
use rustc_span::symbol::{kw, Ident};
34-
use rustc_span::{self, sym, Span};
34+
use rustc_span::{self, sym, ExpnKind, Span};
3535
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
3636

3737
use std::iter;
@@ -1182,6 +1182,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11821182
// Call out where the function is defined
11831183
self.label_fn_like(&mut err, fn_def_id, callee_ty, None, is_method);
11841184

1185+
if !suggestions.iter().all(|(sp, _)| {
1186+
sp.macro_backtrace().all(|data| !matches!(data.kind, ExpnKind::Macro(..)))
1187+
}) {
1188+
// We don't want to provide structured suggestions if macros are involved at all.
1189+
err.emit();
1190+
return;
1191+
}
11851192
// And add a suggestion block for all of the parameters
11861193
let suggestion_text = match suggestion_text {
11871194
SuggestionText::None => None,

tests/ui/argument-suggestions/extra_arguments.stderr

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,6 @@ note: function defined here
266266
LL | fn empty() {}
267267
| ^^^^^
268268
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
269-
help: remove the extra arguments
270-
|
271-
LL ~ empty($x, );
272-
LL | }
273-
...
274-
LL | );
275-
LL ~ foo!();
276-
|
277269

278270
error: aborting due to 16 previous errors
279271

tests/ui/issues/issue-26094.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ fn some_function() {} //~ NOTE defined here
99
fn main() {
1010
some_macro!(some_function);
1111
//~^ ERROR function takes 0 arguments but 1 argument was supplied
12-
//~| NOTE in this expansion of some_macro!
1312
}

tests/ui/issues/issue-26094.stderr

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied
22
--> $DIR/issue-26094.rs:10:17
33
|
44
LL | $other(None)
5-
| ----
6-
| |
7-
| unexpected argument of type `Option<_>`
8-
| help: remove the extra argument
5+
| ---- unexpected argument of type `Option<_>`
96
...
107
LL | some_macro!(some_function);
118
| ^^^^^^^^^^^^^

0 commit comments

Comments
 (0)