• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 use proc_macro2::{Delimiter, Group};
2 use quote::quote;
3 
4 #[test]
main()5 fn main() {
6     // Okay. Rustc allows top-level `static` with no value syntactically, but
7     // not semantically. Syn parses as Item::Verbatim.
8     let tokens = quote! {
9         pub static FOO: usize;
10         pub static BAR: usize;
11     };
12     let file = syn::parse2::<syn::File>(tokens).unwrap();
13     println!("{:#?}", file);
14 
15     // Okay.
16     let inner = Group::new(
17         Delimiter::None,
18         quote!(static FOO: usize = 0; pub static BAR: usize = 0),
19     );
20     let tokens = quote!(pub #inner;);
21     let file = syn::parse2::<syn::File>(tokens).unwrap();
22     println!("{:#?}", file);
23 
24     // Formerly parser crash.
25     let inner = Group::new(
26         Delimiter::None,
27         quote!(static FOO: usize; pub static BAR: usize),
28     );
29     let tokens = quote!(pub #inner;);
30     let file = syn::parse2::<syn::File>(tokens).unwrap();
31     println!("{:#?}", file);
32 }
33