about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCaleb Cartwright <caleb.cartwright@outlook.com>2023-05-12 16:57:29 -0500
committerCaleb Cartwright <caleb.cartwright@outlook.com>2023-05-13 16:59:28 -0500
commit00c3f7552ebaef26165da93ef2c88a09ba70d5c2 (patch)
treec1ee2b1920163389c81fc546f2af5602b6fce835
parent2c41369acc445d04129db40ba998dd7a89fb0d2e (diff)
downloadrust-00c3f7552ebaef26165da93ef2c88a09ba70d5c2.tar.gz
rust-00c3f7552ebaef26165da93ef2c88a09ba70d5c2.zip
refactor: add chunks method to TokenStream to obviate rustdoc clones
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs4
-rw-r--r--src/librustdoc/clean/utils.rs3
2 files changed, 5 insertions, 2 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index 3f0b1627afa..db296aa44db 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -551,6 +551,10 @@ impl TokenStream {
             vec_mut.extend(stream_iter);
         }
     }
+
+    pub fn chunks(&self, chunk_size: usize) -> core::slice::Chunks<'_, TokenTree> {
+        self.0.chunks(chunk_size)
+    }
 }
 
 /// By-reference iterator over a [`TokenStream`], that produces `&TokenTree`
diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs
index b802fd065fe..17aa6b38e38 100644
--- a/src/librustdoc/clean/utils.rs
+++ b/src/librustdoc/clean/utils.rs
@@ -594,9 +594,8 @@ pub(super) fn display_macro_source(
     def_id: DefId,
     vis: ty::Visibility<DefId>,
 ) -> String {
-    let tts: Vec<_> = def.body.tokens.clone().into_trees().collect();
     // Extract the spans of all matchers. They represent the "interface" of the macro.
-    let matchers = tts.chunks(4).map(|arm| &arm[0]);
+    let matchers = def.body.tokens.chunks(4).map(|arm| &arm[0]);
 
     if def.macro_rules {
         format!("macro_rules! {} {{\n{}}}", name, render_macro_arms(cx.tcx, matchers, ";"))