55//! handle same-named functions, simple functions, and cross-file moves.
66
77use smart_diff_parser:: { Change , ChangeType , CodeElement , Function , MatchResult } ;
8- use std:: collections:: { HashMap , HashSet } ;
8+ use std:: collections:: HashSet ;
99
1010/// Configuration for smart matching
1111#[ derive( Debug , Clone ) ]
@@ -209,7 +209,7 @@ impl SmartMatcher {
209209 score += body_weight * body_sim;
210210 weight += body_weight;
211211
212- let mut final_score = if weight > 0.0 { score / weight } else { 0.0 } ;
212+ let final_score = if weight > 0.0 { score / weight } else { 0.0 } ;
213213
214214 // Rule 3a: Stricter matching for different-named functions
215215 // If names are different, require high body similarity to avoid matching
@@ -227,7 +227,7 @@ impl SmartMatcher {
227227 return 0.0 ;
228228 }
229229 // For moderately similar names (0.5-0.8), require 92% body similarity
230- if name_sim >= 0.5 && name_sim < 0.8 && body_sim < 0.92 {
230+ if ( 0.5 .. 0.8 ) . contains ( & name_sim ) && body_sim < 0.92 {
231231 return 0.0 ;
232232 }
233233 // For very different names (< 0.5), require 95% body similarity
@@ -249,18 +249,18 @@ impl SmartMatcher {
249249 /// Check if a function is "simple" (small body, likely a getter/setter/wrapper)
250250 fn is_simple_function ( & self , func : & Function ) -> bool {
251251 // Count non-empty nodes in the body
252- let node_count = self . count_ast_nodes ( & func. body ) ;
252+ let node_count = Self :: count_ast_nodes ( & func. body ) ;
253253 // Simple functions: single statement wrappers, getters, setters
254254 // Typically have 10 or fewer AST nodes
255255 node_count <= 10
256256 }
257257
258258 /// Count AST nodes recursively
259- fn count_ast_nodes ( & self , node : & smart_diff_parser:: ASTNode ) -> usize {
259+ fn count_ast_nodes ( node : & smart_diff_parser:: ASTNode ) -> usize {
260260 1 + node
261261 . children
262262 . iter ( )
263- . map ( |child| self . count_ast_nodes ( child) )
263+ . map ( |child| Self :: count_ast_nodes ( child) )
264264 . sum :: < usize > ( )
265265 }
266266
@@ -271,11 +271,11 @@ impl SmartMatcher {
271271 body2 : & smart_diff_parser:: ASTNode ,
272272 ) -> f64 {
273273 // Simple structural similarity based on node count and depth
274- let count1 = self . count_ast_nodes ( body1) ;
275- let count2 = self . count_ast_nodes ( body2) ;
274+ let count1 = Self :: count_ast_nodes ( body1) ;
275+ let count2 = Self :: count_ast_nodes ( body2) ;
276276
277- let depth1 = self . calculate_ast_depth ( body1) ;
278- let depth2 = self . calculate_ast_depth ( body2) ;
277+ let depth1 = Self :: calculate_ast_depth ( body1) ;
278+ let depth2 = Self :: calculate_ast_depth ( body2) ;
279279
280280 // Node count similarity (60%)
281281 let count_sim = if count1. max ( count2) == 0 {
@@ -301,14 +301,14 @@ impl SmartMatcher {
301301 }
302302
303303 /// Calculate AST depth
304- fn calculate_ast_depth ( & self , node : & smart_diff_parser:: ASTNode ) -> usize {
304+ fn calculate_ast_depth ( node : & smart_diff_parser:: ASTNode ) -> usize {
305305 if node. children . is_empty ( ) {
306306 1
307307 } else {
308308 1 + node
309309 . children
310310 . iter ( )
311- . map ( |child| self . calculate_ast_depth ( child) )
311+ . map ( |child| Self :: calculate_ast_depth ( child) )
312312 . max ( )
313313 . unwrap_or ( 0 )
314314 }
0 commit comments