diff --git a/src/lib.rs b/src/lib.rs index b77a05e7..ab680a2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,8 +15,7 @@ extern crate syntax; use syntax::ast; use syntax::codemap::Spanned; use syntax::ext::base::ExtCtxt; -use syntax::parse::token; -use syntax::parse; +use syntax::parse::{self, classify, token}; use syntax::ptr::P; use std::rc::Rc; @@ -133,7 +132,16 @@ impl ToTokens for ast::WhereClause { impl ToTokens for P { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec { - vec![ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone())))] + let mut tts = vec![ + ast::TtToken(self.span, token::Interpolated(token::NtStmt(self.clone()))) + ]; + + // Some statements require a trailing semicolon. + if classify::stmt_ends_with_semi(&self.node) { + tts.push(ast::TtToken(self.span, token::Semi)); + } + + tts } } diff --git a/tests/test.rs b/tests/test.rs index 93c4c911..38bc0563 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -241,3 +241,18 @@ fn test_quote_with_generics_and_where_clause() { "impl Clone for Foo where T: Clone { }" ); } + +#[test] +fn test_stmt_semicolons() { + let sess = parse::new_parse_sess(); + let cx = make_ext_ctxt(&sess); + + let stmts = vec![ + quote_stmt!(&cx, "let x = 1;"), + quote_stmt!(&cx, "let x = 2;"), + ]; + + quote_block!(&cx, { + $stmts + }).ok().unwrap(); +}