dtolnay / quote

Rust quasi-quoting

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Punct spacing is not preserved

vldm opened this issue · comments

During testing custom punctuation in syn, i have found that it is impossible to write tests using quote.
Debugging lead me to the minimal test:

#[cfg(test)]
mod test {
    use quote::quote;
    use proc_macro2::{TokenTree, Spacing};

    #[test]
    fn it_works() {
        let mut tts = quote!(<>).into_iter();
        let TokenTree::Punct(c) = tts.next().unwrap() else { panic!() };
        assert_eq!(c.spacing(), Spacing::Joint)
    }
}

Output:

thread 'test::it_works' panicked at 'assertion failed: `(left == right)`
  left: `Alone`,
 right: `Joint`', src/lib.rs:10:9

If i understand correctly, Rustc will produce Spacing::Joint for similar token stream.

I don't know any other way to implement this, but I would be prepared to consider a PR if someone else has a way.

Thanks, for fast response.
Maybe implementation on procedural macro can solve this?
Is there any reason to keep quote declarative?

I have found few issues #82 #113 that mention, that the main purpose is the speed.

Do you have some repo for benchmarks(or guide how one can measure perfomance of its own macro)? (very interested to apply it for my project)