Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/services/analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ impl AnalyzerService {
target_row: usize,
) -> Option<tree_sitter::Node<'_>> {
for i in 0..parent.child_count() {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
if let Some(child) = parent.child(i as u32)
&& child.start_position().row <= target_row
Expand Down Expand Up @@ -530,6 +531,7 @@ impl AnalyzerService {
fn has_java_public_modifier(node: tree_sitter::Node) -> bool {
let child_count = node.child_count();
for i in 0..child_count {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
if let Some(child) = node.child(i as u32)
&& child.kind() == "modifiers"
Expand Down Expand Up @@ -564,6 +566,7 @@ impl AnalyzerService {
.or_else(|| {
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand Down Expand Up @@ -633,6 +636,7 @@ impl AnalyzerService {
fn has_csharp_public_modifier(node: tree_sitter::Node) -> bool {
let child_count = node.child_count();
for i in 0..child_count {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
if let Some(child) = node.child(i as u32)
&& child.kind() == "modifier"
Expand Down
12 changes: 12 additions & 0 deletions src/services/differ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ impl AstDiffer {
// Find body-like node that contains field or variant definitions
let body = (0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -169,6 +170,7 @@ impl AstDiffer {

if let Some(b) = body {
for i in 0..b.child_count() {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
if let Some(child) = b.child(i as u32) {
// Skip symbols/punc
Expand Down Expand Up @@ -273,6 +275,7 @@ impl AstDiffer {
// Look for type_parameters child (Rust, TS, Java)
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -298,6 +301,7 @@ impl AstDiffer {
let param_node = node.child_by_field_name("parameters").or_else(|| {
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -311,6 +315,7 @@ impl AstDiffer {

if let Some(pnode) = param_node {
for i in 0..pnode.child_count() {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
if let Some(child) = pnode.child(i as u32) {
// Skip delimiters like ( ) ,
Expand Down Expand Up @@ -398,6 +403,7 @@ impl AstDiffer {
// Check for visibility_modifier child (Rust)
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -414,6 +420,7 @@ impl AstDiffer {
fn is_async(node: tree_sitter::Node) -> bool {
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -427,6 +434,7 @@ impl AstDiffer {
fn has_keyword(node: tree_sitter::Node, keyword: &str) -> bool {
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand All @@ -438,6 +446,7 @@ impl AstDiffer {
if c.kind().ends_with("_modifiers") || c.kind() == "modifiers" {
return (0..c.child_count())
.filter_map(|j| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
c.child(j as u32)
})
Expand All @@ -451,6 +460,7 @@ impl AstDiffer {
fn extract_derives(node: tree_sitter::Node, source: &str) -> Vec<String> {
let mut derives = Vec::new();
for i in 0..node.child_count() {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
let Some(child) = node.child(i as u32) else {
continue;
Expand Down Expand Up @@ -493,6 +503,7 @@ impl AstDiffer {
let body = node.child_by_field_name("body").or_else(|| {
(0..node.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
node.child(i as u32)
})
Expand Down Expand Up @@ -527,6 +538,7 @@ mod tests {
let root = tree.root_node();
(0..root.child_count())
.filter_map(|i| {
// SAFETY: tree-sitter nodes cannot have > u32::MAX children; loop index is bounded by child_count().
#[allow(clippy::cast_possible_truncation)]
root.child(i as u32)
})
Expand Down
Loading