-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Closed
Copy link
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)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
The following crate reproduces the issue. Given an attribute macro on a mod item like #[...] mod module;
, iterating over the tokens of the TokenStream produces mod module;
but invoking to_string() on the TokenStream produces mod module { /* the contents */ }
. I don't know which one is correct but they should be consistent.
Cargo.toml
[package]
name = "repro"
version = "0.0.0"
publish = false
[lib]
proc-macro = true
src/main.rs
#![feature(proc_macro)]
extern crate repro;
#[repro::print]
mod module;
fn main() {}
src/module.rs
pub struct S;
src/lib.rs
#![feature(proc_macro)]
extern crate proc_macro;
use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn print(_args: TokenStream, input: TokenStream) -> TokenStream {
println!("{}", input);
for tt in input {
println!("{:?}", tt.kind);
}
TokenStream::empty()
}
Output
mod module {
pub struct S;
}
Term(Term(mod))
Term(Term(module))
Op(';', Alone)
Metadata
Metadata
Assignees
Labels
A-decl-macros-2-0Area: Declarative macros 2.0 (#39412)Area: Declarative macros 2.0 (#39412)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.