Skip to content

Commit 88bbe80

Browse files
committed
Avoid incorrect argument suggestions in macros
1 parent b534f3b commit 88bbe80

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, BytePos, Span};
34+
use rustc_span::{self, sym, BytePos, ExpnKind, Span};
3535
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};
3636

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

1214+
if !suggestions.iter().all(|(sp, _)| {
1215+
sp.macro_backtrace().all(|data| !matches!(data.kind, ExpnKind::Macro(..)))
1216+
}) {
1217+
// We don't want to provide structured suggestions if macros are involved at all.
1218+
err.emit();
1219+
return;
1220+
}
12141221
// And add a suggestion block for all of the parameters
12151222
let suggestion_text = match suggestion_text {
12161223
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/macros/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/macros/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)