Skip to content

Commit ac7f2d1

Browse files
committed
test: Add test for async-move in 2015 Rust proc macro
1 parent 19079cf commit ac7f2d1

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
use proc_macro::*;
8+
9+
#[proc_macro_attribute]
10+
pub fn foo(_attr: TokenStream, item: TokenStream) -> TokenStream {
11+
let tt = item.into_iter().next().unwrap();
12+
let sp = tt.span();
13+
let mut arg = TokenStream::new();
14+
let mut g = Group::new(Delimiter::Brace, TokenStream::new());
15+
g.set_span(sp);
16+
arg.extend([
17+
TokenTree::Ident(Ident::new("async", sp)),
18+
TokenTree::Ident(Ident::new("move", sp)),
19+
TokenTree::Group(g),
20+
]);
21+
let mut body = TokenStream::new();
22+
body.extend([
23+
TokenTree::Ident(Ident::new("async_main", sp)),
24+
TokenTree::Group(Group::new(Delimiter::Parenthesis, arg)),
25+
]);
26+
27+
let mut ret = TokenStream::new();
28+
ret.extend([
29+
TokenTree::Ident(Ident::new("fn", sp)),
30+
TokenTree::Ident(Ident::new("main", sp)),
31+
TokenTree::Group(Group::new(Delimiter::Parenthesis, TokenStream::new())),
32+
TokenTree::Group(Group::new(Delimiter::Brace, body)),
33+
]);
34+
eprintln!("{:?}", ret);
35+
ret
36+
}

tests/ui/proc-macro/issue-89699.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// aux-build:async-move.rs
2+
3+
extern crate async_move;
4+
5+
#[async_move::foo]
6+
fn foo() {} //~ ERROR `async move` blocks are only allowed in Rust 2018 or later
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
TokenStream [Ident { ident: "fn", span: #0 bytes(73..75) }, Ident { ident: "main", span: #0 bytes(73..75) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #5 bytes(54..72) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "async_main", span: #0 bytes(73..75) }, Group { delimiter: Parenthesis, stream: TokenStream [Ident { ident: "async", span: #0 bytes(73..75) }, Ident { ident: "move", span: #0 bytes(73..75) }, Group { delimiter: Brace, stream: TokenStream [], span: #0 bytes(73..75) }], span: #5 bytes(54..72) }], span: #5 bytes(54..72) }]
2+
error: `async move` blocks are only allowed in Rust 2018 or later
3+
--> $DIR/issue-89699.rs:6:1
4+
|
5+
LL | fn foo() {}
6+
| ^^
7+
8+
error: aborting due to previous error
9+

0 commit comments

Comments
 (0)