From ad566b78f21d58c2a25feeba06fc9506fe514b46 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 19 Apr 2022 14:15:30 +1000 Subject: [PATCH] Tweak `Cursor::next_with_spacing`. This makes it more like `CursorRef::next_with_spacing`. There is no performance effect, just a consistency improvement. --- compiler/rustc_ast/src/tokenstream.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index affb4289cb1..a4057043e48 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -586,12 +586,10 @@ impl Cursor { } pub fn next_with_spacing(&mut self) -> Option { - if self.index < self.stream.len() { + self.stream.0.get(self.index).map(|tree| { self.index += 1; - Some(self.stream.0[self.index - 1].clone()) - } else { - None - } + tree.clone() + }) } pub fn index(&self) -> usize {