From 5e1daf0c4197d4eff7af0031d9467682cf565cfe Mon Sep 17 00:00:00 2001 From: Will Lillis Date: Sat, 2 Aug 2025 17:58:40 -0400 Subject: [PATCH] fix(rust)!: take `u32` for index parameter to `Node::{child, named_child}` Co-authored-by: Ye Sijun --- crates/cli/src/fuzz/corpus_test.rs | 2 +- crates/cli/src/parse.rs | 2 +- lib/binding_rust/lib.rs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/fuzz/corpus_test.rs b/crates/cli/src/fuzz/corpus_test.rs index 8807d9a9..e95ab283 100644 --- a/crates/cli/src/fuzz/corpus_test.rs +++ b/crates/cli/src/fuzz/corpus_test.rs @@ -23,7 +23,7 @@ pub fn check_consistent_sizes(tree: &Tree, input: &[u8]) { let mut some_child_has_changes = false; let mut actual_named_child_count = 0; for i in 0..node.child_count() { - let child = node.child(i).unwrap(); + let child = node.child(i as u32).unwrap(); assert!(child.start_byte() >= last_child_end_byte); assert!(child.start_position() >= last_child_end_point); check(child, line_offsets); diff --git a/crates/cli/src/parse.rs b/crates/cli/src/parse.rs index bc01a908..d6966f72 100644 --- a/crates/cli/src/parse.rs +++ b/crates/cli/src/parse.rs @@ -572,7 +572,7 @@ pub fn parse_file_at_path( write!(&mut stdout, "", tag.expect("there is a tag"))?; // we only write a line in the case where it's the last sibling if let Some(parent) = node.parent() { - if parent.child(parent.child_count() - 1).unwrap() == node { + if parent.child(parent.child_count() as u32 - 1).unwrap() == node { stdout.write_all(b"\n")?; } } diff --git a/lib/binding_rust/lib.rs b/lib/binding_rust/lib.rs index f50c4495..e7d0821f 100644 --- a/lib/binding_rust/lib.rs +++ b/lib/binding_rust/lib.rs @@ -1765,8 +1765,8 @@ impl<'tree> Node<'tree> { /// [`Node::children`] instead. #[doc(alias = "ts_node_child")] #[must_use] - pub fn child(&self, i: usize) -> Option { - Self::new(unsafe { ffi::ts_node_child(self.0, i as u32) }) + pub fn child(&self, i: u32) -> Option { + Self::new(unsafe { ffi::ts_node_child(self.0, i) }) } /// Get this node's number of children. @@ -1784,8 +1784,8 @@ impl<'tree> Node<'tree> { /// [`Node::named_children`] instead. #[doc(alias = "ts_node_named_child")] #[must_use] - pub fn named_child(&self, i: usize) -> Option { - Self::new(unsafe { ffi::ts_node_named_child(self.0, i as u32) }) + pub fn named_child(&self, i: u32) -> Option { + Self::new(unsafe { ffi::ts_node_named_child(self.0, i) }) } /// Get this node's number of *named* children.