diff options
| author | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-01 23:39:00 +1000 |
|---|---|---|
| committer | Huon Wilson <dbau.pp+github@gmail.com> | 2014-05-02 22:54:55 +1000 |
| commit | 1d43a98deadf9d1866d99e253db14651c36726e3 (patch) | |
| tree | 6e087689d8f77021267368459d81de613c060bfb | |
| parent | 5c424ba34ad8b45cfba4619832d23b0278ede696 (diff) | |
| download | rust-1d43a98deadf9d1866d99e253db14651c36726e3.tar.gz rust-1d43a98deadf9d1866d99e253db14651c36726e3.zip | |
syntax: implement ToSource for more things in the quasiquoter.
The last few primitive types were missing.
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 23 | ||||
| -rw-r--r-- | src/test/run-pass-fulldeps/quote-tokens.rs | 4 |
2 files changed, 27 insertions, 0 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 68b0ef40b16..fc7f7722354 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -125,6 +125,26 @@ pub mod rt { } } + impl ToSource for () { + fn to_source(&self) -> ~str { + "()".to_owned() + } + } + + impl ToSource for bool { + fn to_source(&self) -> ~str { + let lit = dummy_spanned(ast::LitBool(*self)); + pprust::lit_to_str(&lit) + } + } + + impl ToSource for char { + fn to_source(&self) -> ~str { + let lit = dummy_spanned(ast::LitChar(*self)); + pprust::lit_to_str(&lit) + } + } + impl ToSource for int { fn to_source(&self) -> ~str { let lit = dummy_spanned(ast::LitInt(*self as i64, ast::TyI)); @@ -227,6 +247,9 @@ pub mod rt { impl_to_tokens!(@ast::Expr) impl_to_tokens!(ast::Block) impl_to_tokens_self!(&'a str) + impl_to_tokens!(()) + impl_to_tokens!(char) + impl_to_tokens!(bool) impl_to_tokens!(int) impl_to_tokens!(i8) impl_to_tokens!(i16) diff --git a/src/test/run-pass-fulldeps/quote-tokens.rs b/src/test/run-pass-fulldeps/quote-tokens.rs index 4243fcb05d5..7c25246807d 100644 --- a/src/test/run-pass-fulldeps/quote-tokens.rs +++ b/src/test/run-pass-fulldeps/quote-tokens.rs @@ -26,6 +26,10 @@ fn syntax_extension(cx: &ExtCtxt) { let _c: @syntax::ast::Pat = quote_pat!(cx, (x, 1 .. 4, *) ); let _d: @syntax::ast::Stmt = quote_stmt!(cx, let x = $a; ); let _e: @syntax::ast::Expr = quote_expr!(cx, match foo { $p_toks => 10 } ); + + let _f: @syntax::ast::Expr = quote_expr!(cx, ()); + let _g: @syntax::ast::Expr = quote_expr!(cx, true); + let _h: @syntax::ast::Expr = quote_expr!(cx, 'a'); } fn main() { |
