about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/tokenstream.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-12-11 14:58:19 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-12-18 10:43:28 +1100
commitc82d5865f2f556464a14951686897989223a8d0a (patch)
treefce8c89e167ae7c0153891671d7586fe15467a90 /compiler/rustc_ast/src/tokenstream.rs
parent809975c94aa8dd69775a0caff819ebb0c81d1966 (diff)
downloadrust-c82d5865f2f556464a14951686897989223a8d0a.tar.gz
rust-c82d5865f2f556464a14951686897989223a8d0a.zip
Remove `Peekable<TokenStreamIter>` uses.
Currently there are two ways to peek at a `TokenStreamIter`.
- Wrap it in a `Peekable` and use that traits `peek` method.
- Use `TokenStreamIter`'s inherent `peek` method.

Some code uses one, some use the other. This commit converts all places
to the inherent method. This eliminates mixing of `TokenStreamIter` and
`Peekable<TokenStreamIter>` and some use of `impl Iterator` and `dyn
Iterator`.
Diffstat (limited to 'compiler/rustc_ast/src/tokenstream.rs')
-rw-r--r--compiler/rustc_ast/src/tokenstream.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs
index 9f7ba928692..9f7a583af09 100644
--- a/compiler/rustc_ast/src/tokenstream.rs
+++ b/compiler/rustc_ast/src/tokenstream.rs
@@ -676,7 +676,10 @@ impl<'t> TokenStreamIter<'t> {
         TokenStreamIter { stream, index: 0 }
     }
 
-    pub fn peek(&self) -> Option<&TokenTree> {
+    // Peeking could be done via `Peekable`, but most iterators need peeking,
+    // and this is simple and avoids the need to use `peekable` and `Peekable`
+    // at all the use sites.
+    pub fn peek(&self) -> Option<&'t TokenTree> {
         self.stream.0.get(self.index)
     }
 }