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

Do not provide suggestions when the spans come from expanded code that doesn't point at user code #109082

Closed
wants to merge 14 commits into from
Closed
Prev Previous commit
Next Next commit
Avoid incorrect argument suggestions in macros
  • Loading branch information
estebank committed Apr 26, 2023
commit 88bbe80f25760ad78107df38aafed1f36ee4a476
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 @@ -31,7 +31,7 @@ use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, IsSuggestable, Ty};
use rustc_session::Session;
use rustc_span::symbol::{kw, Ident};
use rustc_span::{self, sym, BytePos, Span};
use rustc_span::{self, sym, BytePos, ExpnKind, Span};
use rustc_trait_selection::traits::{self, ObligationCauseCode, SelectionContext};

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

if !suggestions.iter().all(|(sp, _)| {
sp.macro_backtrace().all(|data| !matches!(data.kind, ExpnKind::Macro(..)))
}) {
// We don't want to provide structured suggestions if macros are involved at all.
err.emit();
return;
}
// And add a suggestion block for all of the parameters
let suggestion_text = match suggestion_text {
SuggestionText::None => None,
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/argument-suggestions/extra_arguments.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,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, );
LL | }
...
LL | );
LL ~ foo!();
|

error: aborting due to 16 previous errors

Expand Down
1 change: 0 additions & 1 deletion tests/ui/macros/issue-26094.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ fn some_function() {} //~ NOTE defined here
fn main() {
some_macro!(some_function);
//~^ ERROR function takes 0 arguments but 1 argument was supplied
//~| NOTE in this expansion of some_macro!
}
5 changes: 1 addition & 4 deletions tests/ui/macros/issue-26094.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/issue-26094.rs:10:17
|
LL | $other(None)
| ----
| |
| unexpected argument of type `Option<_>`
| help: remove the extra argument
| ---- unexpected argument of type `Option<_>`
...
LL | some_macro!(some_function);
| ^^^^^^^^^^^^^
Expand Down