Skip to content

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

Closed
@subtle-byte

Description

@subtle-byte

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.

Metadata

Metadata

Assignees

Labels

A-proc-macrosArea: Procedural macrosC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions