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

quote!(false) produces a different set of tokens than parsing the string "false" #60

Closed
mystor opened this issue Jan 8, 2018 · 2 comments
Labels

Comments

@mystor
Copy link
Collaborator

mystor commented Jan 8, 2018

extern crate syn;
#[macro_use]
extern crate quote;

use quote::ToTokens;

fn main() {
    println!("{:?}", syn::parse_str::<syn::Expr>("false").unwrap().into_tokens().into_iter().next().unwrap());
    println!("{:?}", quote!(false).into_iter().next().unwrap());
}

output:

$ cargo run
   Compiling syn_test_0 v0.1.0 (file:///home/mlayzell/Code/syn_test_0)
    Finished dev [unoptimized + debuginfo] target(s) in 0.97 secs
     Running `target/debug/syn_test_0`
TokenTree { span: Span, kind: Term(Term("false")) }
TokenTree { span: Span, kind: Literal(Literal("false")) }

From @dtolnay and I talking on IRC, the correct output is Term and not Literal.

@dtolnay dtolnay added the bug label Jan 8, 2018
@dtolnay
Copy link
Owner

dtolnay commented Jan 8, 2018

Running the same thing in a proc macro with proc-macro2/nightly they are both Term, so I guess that is the right answer.

#[proc_macro]
pub fn bug(_input: TokenStream) -> TokenStream {
    println!("{:?}", syn::parse_str::<syn::Expr>("false").unwrap().into_tokens().into_iter().next().unwrap());
    println!("{:?}", quote!(false).into_iter().next().unwrap());
    TokenStream::empty()
}
TokenTree { span: Span(Span { lo: BytePos(5829957), hi: BytePos(5829962), ctxt: #0 }), kind: Term(Term(false)) }
TokenTree { span: Span(Span { lo: BytePos(118), hi: BytePos(133), ctxt: #3 }), kind: Term(Term(false)) }

@mystor
Copy link
Collaborator Author

mystor commented Jan 8, 2018

This is actually a bug in proc_macro2 so closing in favour of dtolnay/proc-macro2#51

@mystor mystor closed this as completed Jan 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants