about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-03-19 20:51:09 -0400
committerGitHub <noreply@github.com>2017-03-19 20:51:09 -0400
commit7471d9793cf21f89f672eff14e6c529e286c2d30 (patch)
tree55ef7bc3a856def3bd1872fffa093acee516f61a /src/libsyntax
parent1d1543d5667ef1dddf03aa1aeed77851b604f704 (diff)
parentce616a7d6ad838aacd080b47566c15e82ad8dd6d (diff)
downloadrust-7471d9793cf21f89f672eff14e6c529e286c2d30.tar.gz
rust-7471d9793cf21f89f672eff14e6c529e286c2d30.zip
Rollup merge of #40532 - jseyfried:improve_tokenstream_quoter, r=nrc
macros: improve the `TokenStream` quoter

This PR
 - renames the `TokenStream` quoter from `qquote!` to `quote!`,
 - uses `$` instead of `unquote` (e.g. `let toks: TokenStream = ...; quote!([$toks])`),
 - allows unquoting `Token`s as well as `TokenTree`s and `TokenStream`s (fixes #39746), and
 - to preserve syntactic space, requires that `$` be followed by
   - a single identifier to unquote, or
   - another `$` to produce a literal `$`.

r? @nrc
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/tokenstream.rs6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs
index 35e4d9eb68a..b75b3efda36 100644
--- a/src/libsyntax/tokenstream.rs
+++ b/src/libsyntax/tokenstream.rs
@@ -162,6 +162,12 @@ impl From<TokenTree> for TokenStream {
     }
 }
 
+impl From<Token> for TokenStream {
+    fn from(token: Token) -> TokenStream {
+        TokenTree::Token(DUMMY_SP, token).into()
+    }
+}
+
 impl<T: Into<TokenStream>> iter::FromIterator<T> for TokenStream {
     fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
         TokenStream::concat(iter.into_iter().map(Into::into).collect::<Vec<_>>())