From 84b1c8fb43c83b51a80217423b1e32c0730b348b Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Fri, 22 Nov 2024 15:54:48 +0100 Subject: [PATCH] Fix prev_sibling indexing off-by-one The patch f06a2c903caa270e977a73ef5b9091f99e8fbe6c changed the code to use skip instead of nth, which lead to an off-by-one bug that was uncovered by unit tests in ludtwig, see [1]. [1]: https://github.com/MalteJanz/ludtwig/pull/122 Fixes: https://github.com/rust-analyzer/rowan/issues/175 --- Cargo.toml | 2 +- src/cursor.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 34c84bb..e2bc8c4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rowan" -version = "0.16.0" +version = "0.16.1" authors = ["Aleksey Kladov "] repository = "https://github.com/rust-analyzer/rowan" license = "MIT OR Apache-2.0" diff --git a/src/cursor.rs b/src/cursor.rs index 6b220af..cb6ceeb 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -408,7 +408,7 @@ impl NodeData { let rev_siblings = self.green_siblings().enumerate().rev(); let index = rev_siblings.len().checked_sub(self.index() as usize)?; - rev_siblings.skip(index + 1).find_map(|(index, child)| { + rev_siblings.skip(index).find_map(|(index, child)| { child.as_ref().into_node().and_then(|green| { let parent = self.parent_node()?; let offset = parent.offset() + child.rel_offset();