diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-05-15 10:58:40 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-15 10:58:40 +0200 |
| commit | 916ba6dec1b5d223c1fdb8799cc1f0b57d404115 (patch) | |
| tree | d3aec1af8a078bb24f7dde317792ff88d8c28172 | |
| parent | be8718a80bd3a45a03efbe534578df359f765472 (diff) | |
| parent | 00c3f7552ebaef26165da93ef2c88a09ba70d5c2 (diff) | |
| download | rust-916ba6dec1b5d223c1fdb8799cc1f0b57d404115.tar.gz rust-916ba6dec1b5d223c1fdb8799cc1f0b57d404115.zip | |
Rollup merge of #111548 - calebcartwright:by-ref-tokentree2, r=compiler-errors
add util function to TokenStream to eliminate some clones Another proposed change in the same vein as #111492 trying to get rid of some clones. This adds a TokenStream helper function so that rustdoc can directly get a chunks iterator over the underlying token trees so that it no longer needs the clones and vec.
| -rw-r--r-- | compiler/rustc_ast/src/tokenstream.rs | 4 | ||||
| -rw-r--r-- | src/librustdoc/clean/utils.rs | 3 |
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, ";")) |
