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.

Activity

self-assigned this
on Jan 30, 2021
added a commit that references this issue on Jan 31, 2021
6c14aad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

    Participants

    @Aaron1011@subtle-byte

    Issue actions

      Too general error for trivial macro when generated function has invalid name · Issue #81543 · rust-lang/rust