Skip to content

Commit 96072d6

Browse files
committed
syntax: Generalize ToTokens impl for Vec<T>
It will now `flat_map` over the elements of a `Vec<T>` if `T: ToTokens`
1 parent 8659889 commit 96072d6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/libsyntax/ext/quote.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,10 @@ pub mod rt {
5454
}
5555
}
5656

57-
impl ToTokens for Vec<TokenTree> {
58-
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
59-
(*self).clone()
57+
impl<T: ToTokens> ToTokens for Vec<T> {
58+
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
59+
let a = self.iter().flat_map(|t| t.to_tokens(cx).move_iter());
60+
FromIterator::from_iter(a)
6061
}
6162
}
6263

0 commit comments

Comments
 (0)