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

Fallback handling of negative integer literals is different to proc_macro #235

Closed
Kestrer opened this issue May 30, 2020 · 2 comments · Fixed by #236
Closed

Fallback handling of negative integer literals is different to proc_macro #235

Kestrer opened this issue May 30, 2020 · 2 comments · Fixed by #236
Labels

Comments

@Kestrer
Copy link
Contributor

Kestrer commented May 30, 2020

This crate's fallback implementation of From<TokenTree> for TokenStream treats negative integer literals as one token, however rustc's implementation treats negative integer literals as an alone - followed by the positive integer literal.

How to Reproduce

  1. Make a simple proc-macro crate, with this code:
use std::iter;
use proc_macro2::{TokenStream, TokenTree, Literal};

#[proc_macro]
pub fn proc_macro_test(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    //proc_macro2::fallback::force();

    let int: i32 = -3;
    let mut tokens = TokenStream::new();
    tokens.extend(iter::once(TokenTree::Literal(Literal::i32_suffixed(int))));
    dbg!(&tokens);

    input
}
  1. Run that proc macro in another crate. With the commented line commented it will output two separate tokens, but with it uncommented it will output one negative literal token.
@dtolnay
Copy link
Owner

dtolnay commented May 31, 2020

Fixed in 1.0.18.

@dtolnay
Copy link
Owner

dtolnay commented May 31, 2020

FWIW I think our original behavior was better. It may be worth following up in libproc_macro.

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

Successfully merging a pull request may close this issue.

2 participants