diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 68b0ef40b16b..fc7f77223547 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 4243fcb05d5c..7c25246807d5 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() {