Skip to content

proc-macro param attrs dropping first attrs in impl fns #64682

Closed
@bbqsrc

Description

@bbqsrc

I have been able to reproduce #64282.

If an fn inside an impl has a param attr on the first parameter, no matter how many, they are not visible in the TokenStream.

Repro repo: https://github.com/bbqsrc/params-attribute-example

Source:

#[rename_params(send_help)]
fn hello(#[angery(true)] a: i32, #[a2] b: i32, #[what = "how"] c: u32) {}

#[rename_params(send_help)]
impl Foo {
  fn hello(#[angery(true)] a: i32, #[a2] b: i32, #[what = "how"] c: u32) {}
  fn hello2(#[a1] #[a2] a: i32, #[what = "how"] b: i32, #[angery(true)] c: u32) {}
  fn hello_self(#[a1] #[a2] &self, #[a1] #[a2] a: i32, #[what = "how"] b: i32, #[angery(true)] c: u32) {}
}

Printed output:

fn hello(#[angery(true)] a: i32, #[a2] b: i32, #[what = "how"] c: u32) { }
impl Foo {
    fn hello(a: i32, #[a2] b: i32, #[what = "how"] c: u32) { }
    fn hello2(a: i32, #[what = "how"] b: i32, #[angery(true)] c: u32) { }
    fn hello_self(#[a1] #[a2] &self, #[a1] #[a2] a: i32,
                  #[what = "how"] b: i32, #[angery(true)] c: u32) {
    }
}

As you can see, hello and hello2 are missing their attrs on the a param. The addition of self however gives both self and the a param their attrs. Weird.

$ rustc --version
rustc 1.39.0-nightly (ed8b708c1 2019-09-21)

Metadata

Metadata

Assignees

Labels

A-attributesArea: Attributes (`#[…]`, `#![…]`)A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-bugCategory: This is a bug.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions