diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-19 14:15:30 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-04-19 17:02:48 +1000 |
| commit | ad566b78f21d58c2a25feeba06fc9506fe514b46 (patch) | |
| tree | df9358a25f07efeb0164ced6a58c29540b8287e2 | |
| parent | 8305398d7ae6128811ec2b3223939bcd067530c2 (diff) | |
| download | rust-ad566b78f21d58c2a25feeba06fc9506fe514b46.tar.gz rust-ad566b78f21d58c2a25feeba06fc9506fe514b46.zip | |
Tweak `Cursor::next_with_spacing`.
This makes it more like `CursorRef::next_with_spacing`. There is no performance effect, just a consistency improvement.
| -rw-r--r-- | compiler/rustc_ast/src/tokenstream.rs | 8 |
1 files 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<TreeAndSpacing> { - 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 { |
