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

0 < -1 becomes 0 <- 1 inside macro_rules when proc-macro2 has feature nightly #425

Closed
CodeSandwich opened this issue May 12, 2018 · 2 comments

Comments

@CodeSandwich
Copy link

CodeSandwich commented May 12, 2018

When proc-macro2 has set feature nightly, parsing inside macro_rules becomes buggy. 0 < -1, which is comparison gets glued into 0 <- 1, which is assignment.

Reproduction

Tested using rustc 1.27.0-nightly (acd3871 2018-05-10).

Macro Cargo.toml

[package]
name = "macros"
version = "0.1.0"
[lib]
proc-macro = true
[dependencies]
syn = { version = "0.13.10", features = ["full"] }
quote = "0.5.2"
proc-macro2 = { version = "0.3.8" }

Macro lib.rs

#![feature(proc_macro)]
extern crate proc_macro;
extern crate proc_macro2;
extern crate syn;
extern crate quote;
use proc_macro::TokenStream;
use quote::ToTokens;
#[proc_macro_attribute]
pub fn nothing(_: TokenStream, token_stream: TokenStream) -> TokenStream {
    let tokens = syn::parse::<syn::Item>(token_stream)
        .unwrap()
        .into_tokens()
        .into();
    println!("{}", tokens);
    tokens
}

Macro user lib.rs

#![feature(proc_macro)]
#![allow(unused_macros)]
extern crate macros;
use macros::nothing;
#[nothing]
macro_rules! mr {
    () => { 0 < -1 }
}

Output

macro_rules ! mr ( (  ) => { 0 < - 1 } ) ;

Macro Cargo.toml modification

proc-macro2 = { version = "0.3.8", features = ["nightly"] }

Output after modification

macro_rules ! mr ( (  ) => { 0 <- 1 } ) ;
@dtolnay
Copy link
Owner

dtolnay commented May 12, 2018

Thanks! This is a compiler bug -- I filed rust-lang/rust#50700 to follow up.

@dtolnay dtolnay closed this as completed May 12, 2018
@CodeSandwich
Copy link
Author

Thank you very much :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants