- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Closed
Copy link
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
I have the following proc macro to print out tokens:
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro]
pub fn print_tts(input: TokenStream) -> TokenStream {
    println!("{:#?}", input);
    TokenStream::new()
}And suppose I call it like this:
#![feature(proc_macro_hygiene)]
extern crate print;
macro_rules! print_ident {
    ($i:ident) => {
        print::print_tts!(2 * $i)
    };
}
fn main() {
    print_ident!(ident);
}As of rustc 1.31.0-nightly (1cf82fd 2018-10-30) the input is passed to my macro as:
TokenStream [
    Literal {
        lit: Integer(
            2
        ),
        suffix: None,
        span: #2 bytes(127..128)
    },
    Punct {
        ch: '*',
        spacing: Alone,
        span: #2 bytes(129..130)
    },
    Group {
        delimiter: None,
        stream: TokenStream [
            Ident {
                ident: "ident",
                span: #0 bytes(174..179)
            }
        ],
        span: #2 bytes(131..133)
    }
]I believe idents (and any other metavariables which are always a single token) should not be wrapped in a Group. It makes handling proc macro input unnecessarily confusing. This proc macro should be receiving a plain Literal Punct Ident rather than Literal Punct Group.
Metavariables that can be multiple tokens, including 
Metadata
Metadata
Assignees
Labels
A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.