]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #49734 - alexcrichton:generalize-token-stream, r=nikomatsakis
authorkennytm <kennytm@gmail.com>
Wed, 11 Apr 2018 19:37:12 +0000 (03:37 +0800)
committerkennytm <kennytm@gmail.com>
Wed, 11 Apr 2018 19:37:12 +0000 (03:37 +0800)
proc_macro: Generalize `FromIterator` impl

While never intended to be stable we forgot that trait impls are insta-stable!
This construction of `FromIterator` wasn't our first choice of how to stabilize
the impl but our hands are tied at this point, so revert back to the original
definition of `FromIterator` before #49597

Closes #49725

src/libproc_macro/lib.rs

index dafdacfdd7247d02d19679d1dd99883fa5d99302..e171216523a1e3a6dd1ea35bf6c06d20868045d8 100644 (file)
@@ -140,9 +140,16 @@ fn from(tree: TokenTree) -> TokenStream {
 #[unstable(feature = "proc_macro", issue = "38356")]
 impl iter::FromIterator<TokenTree> for TokenStream {
     fn from_iter<I: IntoIterator<Item = TokenTree>>(trees: I) -> Self {
+        trees.into_iter().map(TokenStream::from).collect()
+    }
+}
+
+#[unstable(feature = "proc_macro", issue = "38356")]
+impl iter::FromIterator<TokenStream> for TokenStream {
+    fn from_iter<I: IntoIterator<Item = TokenStream>>(streams: I) -> Self {
         let mut builder = tokenstream::TokenStreamBuilder::new();
-        for tree in trees {
-            builder.push(tree.to_internal());
+        for stream in streams {
+            builder.push(stream.0);
         }
         TokenStream(builder.build())
     }