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

mut keyword is lost when parsing a fn #632

Closed
kjvalencik opened this issue May 9, 2019 · 4 comments
Closed

mut keyword is lost when parsing a fn #632

kjvalencik opened this issue May 9, 2019 · 4 comments

Comments

@kjvalencik
Copy link

if let syn::Item::Fn(mut function_item) = syn::parse(item.clone()).unwrap() {
$ rustc --version
rustc 1.36.0-nightly (3f5152e20 2019-05-08)
$ cargo version
cargo 1.36.0-nightly (759b6161a 2019-05-06)

Interestingly, &mut works fine.

@dtolnay
Copy link
Owner

dtolnay commented May 9, 2019

Could you share a minimal runnable piece of code for me to reproduce what you are seeing?

Here is what I tried, and the mut keyword was not lost:

use proc_macro2::TokenStream;
use quote::quote;
use syn::Item;

fn main() {
    let code = "fn f(mut x: u8) {}";
    let tokens = code.parse::<TokenStream>().unwrap();
    if let Item::Fn(function_item) = syn::parse2(tokens.clone()).unwrap() {
        println!("tokens: {}\nfunction_item: {}", tokens, quote!(#function_item));
    } else {
        panic!("expected fn");
    }
}

@kjvalencik
Copy link
Author

I'll see if I can come up with something minimal a bit later. This is the macro I was using when I encountered the issue: https://github.com/trezm/Thruster/blob/master/thruster-proc/src/lib.rs#L53-L79

If I rollback to nightly 2019/05/01, the issue does not exist.

@kjvalencik
Copy link
Author

kjvalencik commented May 9, 2019

Doing some quick testing, it appears like it could be related to async fn. I haven't been able to reproduce directly with syn; sounds like it may be a bug in proc_macro as part of rust.

@kjvalencik
Copy link
Author

Closing this issue since it's a problem with rustc. Adding a debug print to the macro shows that the TokenStream is incorrect.

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