Skip to content

Too general error for trivial macro when generated function has invalid name #81543

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
subtle-byte opened this issue Jan 30, 2021 · 0 comments · Fixed by #81608
Closed

Too general error for trivial macro when generated function has invalid name #81543

subtle-byte opened this issue Jan 30, 2021 · 0 comments · Fixed by #81608
Assignees
Labels
A-proc-macros Area: Procedural macros C-bug Category: This is a bug.

Comments

@subtle-byte
Copy link

Macro:

#[proc_macro]
pub fn same(input: TokenStream) -> TokenStream {
    input
}

Usage of the macro:

same! {
    fn 32() {}
}

Error:

error: expected identifier, found `32`
  --> wrapper/src/lib.rs:24:1
   |
24 | / same! {
25 | |     fn 32() {}
26 | | }
   | |_^

I expect a more specific error. For example the usage

same! {
    fn f(a: 32) {}
}

triggers the error:

error: expected type, found `32`
  --> wrapper/src/lib.rs:25:13
   |
25 |     fn f(a: 32) {}
   |             ^^ expected type

- only 32 is pointed!

Meta

I've tried the above using the latest stable (rustc 1.49.0 (e1884a8e3 2020-12-29)) and nightly (rustc 1.51.0-nightly (b12290861 2021-01-29)) versions of the compiler.

@subtle-byte subtle-byte added the C-bug Category: This is a bug. label Jan 30, 2021
@Aaron1011 Aaron1011 added the A-proc-macros Area: Procedural macros label Jan 30, 2021
@Aaron1011 Aaron1011 self-assigned this Jan 30, 2021
@bors bors closed this as completed in 6c14aad Feb 2, 2021
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-proc-macros Area: Procedural macros C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants