File tree 2 files changed +17
-3
lines changed
2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -28,8 +28,7 @@ pub mod rt {
28
28
use ast;
29
29
use codemap:: Spanned ;
30
30
use ext:: base:: ExtCtxt ;
31
- use parse:: token;
32
- use parse;
31
+ use parse:: { self , token, classify} ;
33
32
use ptr:: P ;
34
33
use std:: rc:: Rc ;
35
34
@@ -126,7 +125,16 @@ pub mod rt {
126
125
127
126
impl ToTokens for P < ast:: Stmt > {
128
127
fn to_tokens ( & self , _cx : & ExtCtxt ) -> Vec < TokenTree > {
129
- vec ! [ ast:: TtToken ( self . span, token:: Interpolated ( token:: NtStmt ( self . clone( ) ) ) ) ]
128
+ let mut tts = vec ! [
129
+ ast:: TtToken ( self . span, token:: Interpolated ( token:: NtStmt ( self . clone( ) ) ) )
130
+ ] ;
131
+
132
+ // Some statements require a trailing semicolon.
133
+ if classify:: stmt_ends_with_semi ( & self . node ) {
134
+ tts. push ( ast:: TtToken ( self . span , token:: Semi ) ) ;
135
+ }
136
+
137
+ tts
130
138
}
131
139
}
132
140
Original file line number Diff line number Diff line change @@ -43,6 +43,12 @@ fn syntax_extension(cx: &ExtCtxt) {
43
43
let _n: syntax:: ast:: Attribute = quote_attr ! ( cx, #![ cfg( foo, bar = "baz" ) ] ) ;
44
44
45
45
let _o: Option < P < syntax:: ast:: Item > > = quote_item ! ( cx, fn foo<T : ?Sized >( ) { } ) ;
46
+
47
+ let stmts = vec ! [
48
+ quote_stmt!( cx, let x = 1 ; ) . unwrap( ) ,
49
+ quote_stmt!( cx, let y = 2 ; ) . unwrap( ) ,
50
+ ] ;
51
+ let expr: P < syntax:: ast:: Expr > = quote_expr ! ( cx, x + y) ;
46
52
}
47
53
48
54
fn main ( ) {
You can’t perform that action at this time.
0 commit comments