diff options
| author | bors <bors@rust-lang.org> | 2015-05-15 15:14:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-05-15 15:14:25 +0000 |
| commit | 9bebe5f3bbf2715f9c8606d672a2396216077826 (patch) | |
| tree | 94bca0791705d56a8afe947b4673581a2c921a62 /src/libsyntax/ext | |
| parent | 13a4b83c1a73260b9c34a66d3bde62ff09d01863 (diff) | |
| parent | b62290d421acf39db929f05522c8ce530e031067 (diff) | |
| download | rust-9bebe5f3bbf2715f9c8606d672a2396216077826.tar.gz rust-9bebe5f3bbf2715f9c8606d672a2396216077826.zip | |
Auto merge of #25059 - erickt:pprint, r=acrichto
The recent quote changes unfortunately broke unquoting statements like `let foo = 5` because the parser requires their to be a trailing semicolon in those statements. Along the way I added support for unquoting generics and where clauses as well as better pretty printing of `token::Interpolated`.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index e100b7705d8..e0753b2f6f6 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -28,8 +28,7 @@ pub mod rt { use ast; use codemap::Spanned; use ext::base::ExtCtxt; - use parse::token; - use parse; + use parse::{self, token, classify}; use ptr::P; use std::rc::Rc; @@ -94,6 +93,18 @@ pub mod rt { } } + impl ToTokens for ast::Generics { + fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { + vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtGenerics(self.clone())))] + } + } + + impl ToTokens for ast::WhereClause { + fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { + vec![ast::TtToken(DUMMY_SP, token::Interpolated(token::NtWhereClause(self.clone())))] + } + } + impl ToTokens for P<ast::Item> { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { vec![ast::TtToken(self.span, token::Interpolated(token::NtItem(self.clone())))] @@ -114,7 +125,16 @@ pub mod rt { impl ToTokens for P<ast::Stmt> { fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> { - 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 } } |
