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

Regression of #63210 param attributes not showing in proc-macro TokenStream #64282

Closed
bbqsrc opened this issue Sep 8, 2019 · 5 comments
Closed
Assignees
Labels
A-attributes Area: #[attributes(..)] A-pretty Area: Pretty printing. F-param_attrs `#![feature(param_attrs)]` P-high High priority requires-nightly This issue requires a nightly compiler in some way.

Comments

@bbqsrc
Copy link

bbqsrc commented Sep 8, 2019

It seems #63210 isn't actually fixed.

Run cargo test -- --nocapture and you'll see the TokenStream does not contain any attributes on a parameter: https://github.com/bbqsrc/params-attribute-example

@Centril Centril added C-bug Category: This is a bug. P-high High priority requires-nightly This issue requires a nightly compiler in some way. F-param_attrs `#![feature(param_attrs)]` A-attributes Area: #[attributes(..)] A-pretty Area: Pretty printing. labels Sep 8, 2019
@Centril Centril self-assigned this Sep 8, 2019
@Centril Centril removed the C-bug Category: This is a bug. label Sep 10, 2019
@Centril
Copy link
Contributor

Centril commented Sep 10, 2019

So I investigated the issue and I don't believe there's a bug here. The macro prints out the following:

$ cargo test -- --nocapture
   Compiling params-attribute-example v0.1.0 (/home/centril/programming/rust/params-attribute-example)
send_help fn hello(#[angery(true)] a: i32, b: i32) { }
error[E0658]: the attribute `angery` is currently unknown to the compiler and may have meaning added to it in the future

If you look closely, you will see that before the line with error[E0658]: ... it says send_help ....

If you slightly change the macro into...

extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn rename_params(args: TokenStream, _: TokenStream) -> TokenStream {
    dbg!(&args);
    TokenStream::new()
}

...you will see it more clearly:

$ cargo test -- --nocapture
   Compiling params-attribute-example v0.1.0 (/home/centril/programming/rust/params-attribute-example)
[src/lib.rs:6] &args = TokenStream [
    Ident {
        ident: "send_help",
        span: #0 bytes(88..97),
    },
]
    Finished dev [unoptimized + debuginfo] target(s) in 0.32s
     Running target/debug/deps/params_attribute_example-cca77142e891e7a2

...

This seems to be in order.

@bbqsrc
Copy link
Author

bbqsrc commented Sep 10, 2019

That isn't the problem.

use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn rename_params(args: TokenStream, input: TokenStream) -> TokenStream {
    dbg!(&input);
    input
}
    Ident {
        ident: "fn",
        span: #0 bytes(0..0),
    },
    Ident {
        ident: "hello",
        span: #0 bytes(0..0),
    },
    Group {
        delimiter: Parenthesis,
        stream: TokenStream [
            Ident {
                ident: "a",
                span: #0 bytes(0..0),
            },
            Punct {
                ch: ':',
                spacing: Alone,
                span: #0 bytes(0..0),
            },
            Ident {
                ident: "i32",
                span: #0 bytes(0..0),
            },
            Punct {
                ch: ',',
                spacing: Alone,
                span: #0 bytes(0..0),
            },
            Ident {
                ident: "b",
                span: #0 bytes(0..0),
            },
            Punct {
                ch: ':',
                spacing: Alone,
                span: #0 bytes(0..0),
            },
            Ident {
                ident: "i32",
                span: #0 bytes(0..0),
            },
        ],
        span: #0 bytes(0..0),
    },
    Group {
        delimiter: Brace,
        stream: TokenStream [],
        span: #0 bytes(0..0),
    },
]
error[E0658]: The attribute `angery` is currently unknown to the compiler and may have meaning added to it in the future
 --> proc-macro-tests/rename_params.rs:5:10
  |
5 | fn hello(#[angery(true)] a: i32, #[a2] b: i32) {}
  |          ^^^^^^^^^^^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/29642
  = help: add `#![feature(custom_attribute)]` to the crate attributes to enable

error[E0658]: The attribute `a2` is currently unknown to the compiler and may have meaning added to it in the future
 --> proc-macro-tests/rename_params.rs:5:34
  |
5 | fn hello(#[angery(true)] a: i32, #[a2] b: i32) {}
  |                                  ^^^^^
  |
  = note: for more information, see https://github.com/rust-lang/rust/issues/29642
  = help: add `#![feature(custom_attribute)]` to the crate attributes to enable

error: aborting due to 2 previous errors```

`#[angery(true)]` does not appear in the token stream.

@bbqsrc
Copy link
Author

bbqsrc commented Sep 10, 2019

Mm, in the absolutely most recent nightly, it seems to be working now! :D

@bbqsrc bbqsrc closed this as completed Sep 10, 2019
@Centril
Copy link
Contributor

Centril commented Sep 10, 2019

Odd; I tried this out on nightly-2019-08-05 and it seems to be including angery in the tokenstream output.

@bbqsrc
Copy link
Author

bbqsrc commented Sep 10, 2019

Yup, I was doing something wrong somewhere. 🤷‍♂ Just happy it's working now so I can do the cool things :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: #[attributes(..)] A-pretty Area: Pretty printing. F-param_attrs `#![feature(param_attrs)]` P-high High priority requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

2 participants