|
| 1 | +// force-host |
| 2 | +// no-prefer-dynamic |
| 3 | + |
| 4 | +// Proc macro helper for issue #89699, used by tests/ui/proc-macro/edition-gated-async-move- |
| 5 | +// syntax-issue89699.rs, emitting an `async move` closure. This syntax is only available in |
| 6 | +// editions 2018 and up, but is used in edition 2015 in the test. |
| 7 | + |
| 8 | +#![crate_type = "proc-macro"] |
| 9 | + |
| 10 | +extern crate proc_macro; |
| 11 | +use proc_macro::*; |
| 12 | + |
| 13 | +#[proc_macro_attribute] |
| 14 | +pub fn foo(_attr: TokenStream, item: TokenStream) -> TokenStream { |
| 15 | + let tt = item.into_iter().next().unwrap(); |
| 16 | + let sp = tt.span(); |
| 17 | + let mut arg = TokenStream::new(); |
| 18 | + let mut g = Group::new(Delimiter::Brace, TokenStream::new()); |
| 19 | + g.set_span(sp); |
| 20 | + arg.extend([ |
| 21 | + TokenTree::Ident(Ident::new("async", sp)), |
| 22 | + TokenTree::Ident(Ident::new("move", sp)), |
| 23 | + TokenTree::Group(g), |
| 24 | + ]); |
| 25 | + let mut body = TokenStream::new(); |
| 26 | + body.extend([ |
| 27 | + TokenTree::Ident(Ident::new("async_main", sp)), |
| 28 | + TokenTree::Group(Group::new(Delimiter::Parenthesis, arg)), |
| 29 | + ]); |
| 30 | + |
| 31 | + let mut ret = TokenStream::new(); |
| 32 | + ret.extend([ |
| 33 | + TokenTree::Ident(Ident::new("fn", sp)), |
| 34 | + TokenTree::Ident(Ident::new("main", sp)), |
| 35 | + TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())), |
| 36 | + TokenTree::Group(Group::new(Delimiter::Brace, body)), |
| 37 | + ]); |
| 38 | + ret |
| 39 | +} |
0 commit comments