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

Misplaced suggestion for missing generic parameter in macro invocation #90557

Open
AuroransSolis opened this issue Nov 4, 2021 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@AuroransSolis
Copy link

Given the following code:

struct Example<T, U> {
    foo: T,
    bar: U,
}

macro_rules! impl_example {
    ($($t:ty)+) => {$(
        impl Example<$t> {
            fn baz() {
                println!(":)");
            }
        }
    )}
}

impl_example! { u8 }

The current output is:

error[E0107]: this struct takes 2 generic arguments but 1 generic argument was supplied
  --> src/lib.rs:8:14
   |
8  |         impl Example<$t> {
   |              ^^^^^^^ expected 2 generic arguments
...
16 | impl_example! { u8 }
   | --------------------
   | |               |
   | |               supplied 1 generic argument
   | in this macro invocation
   |
note: struct defined here, with 2 generic parameters: `T`, `U`
  --> src/lib.rs:1:8
   |
1  | struct Example<T, U> {
   |        ^^^^^^^ -  -
   = note: this error originates in the macro `impl_example` (in Nightly builds, run with -Z macro-backtrace for more info)
help: add missing generic argument
   |
16 | impl_example! { u8, U }
   |                   +++

Most of the error message is good up until the help section, whereupon following it (by passing, say, u8, u8 to the macro call) leads to another error:

error: no rules expected the token `,`
  --> src/lib.rs:16:19
   |
6  | macro_rules! impl_example {
   | ------------------------- when calling this macro
...
16 | impl_example! { u8, u8 }
   |                   ^ no rules expected this token in macro call

Asking for another generic parameter is good, but it's being asked for in the wrong place.

As for the versions affected, I've tried it on the stable (1.56.1), nightly (2021-11-02 18bc4bee9710b181b440), and beta (2021-11-01 708d57e288d051a6238e) versions available on the Playground as of the time of writing, and all of them are affected.

@AuroransSolis AuroransSolis added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 2021
estebank added a commit to estebank/rust that referenced this issue Mar 15, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 16, 2023
Do not provide suggestions when the spans come from expanded code that doesn't point at user code

Hide invalid proc-macro suggestions and track spans
coming from proc-macros pointing at attribute.

Effectively, unless the proc-macro keeps user spans,
suggestions will not be produced for the code they
produce.

r? `@ghost`

Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557.

Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 17, 2023
Do not provide suggestions when the spans come from expanded code that doesn't point at user code

Hide invalid proc-macro suggestions and track spans
coming from proc-macros pointing at attribute.

Effectively, unless the proc-macro keeps user spans,
suggestions will not be produced for the code they
produce.

r? ``@ghost``

Fix rust-lang#107113, fix rust-lang#107976, fix rust-lang#107977, fix rust-lang#108748, fix rust-lang#106720, fix rust-lang#90557.

Could potentially address rust-lang#50141, rust-lang#67373, rust-lang#55146, rust-lang#78862, rust-lang#74043, rust-lang#88514, rust-lang#83320, rust-lang#91520, rust-lang#104071. CC rust-lang#50122, rust-lang#76360.
estebank added a commit to estebank/rust that referenced this issue Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
1 participant