extractRustImplItem — `impl Trait for Type` back-reference: positional type-node filter (NEVER the grammar's trait:/type: fields), ≥2 needed, target found by FIRST earlier node of kind struct/enum/class (never trait); ref FROM the type's node, named by the trait's full text.
(&mut self, node: Node<'t>)
| 1027 | /// target found by FIRST earlier node of kind struct/enum/class (never |
| 1028 | /// trait); ref FROM the type's node, named by the trait's full text. |
| 1029 | fn extract_rust_impl_item(&mut self, node: Node<'t>) { |
| 1030 | let has_for = (0..node.child_count()) |
| 1031 | .filter_map(|i| node.child(i)) |
| 1032 | .any(|c| c.kind() == "for" && !c.is_named()); |
| 1033 | if !has_for { |
| 1034 | return; |
| 1035 | } |
| 1036 | let type_idents: Vec<Node> = (0..node.named_child_count()) |
| 1037 | .filter_map(|i| node.named_child(i)) |
| 1038 | .filter(|c| matches!(c.kind(), "type_identifier" | "generic_type" | "scoped_type_identifier")) |
| 1039 | .collect(); |
| 1040 | if type_idents.len() < 2 { |
| 1041 | return; |
| 1042 | } |
| 1043 | let trait_node = type_idents[0]; |
| 1044 | let type_node = type_idents[type_idents.len() - 1]; |
| 1045 | |
| 1046 | let trait_name = self.text(trait_node).to_string(); |
| 1047 | let type_name = if type_node.kind() == "generic_type" { |
| 1048 | (0..type_node.named_child_count()) |
| 1049 | .filter_map(|i| type_node.named_child(i)) |
| 1050 | .find(|c| c.kind() == "type_identifier") |
| 1051 | .map(|c| self.text(c).to_string()) |
| 1052 | .unwrap_or_else(|| self.text(type_node).to_string()) |
| 1053 | } else { |
| 1054 | self.text(type_node).to_string() |
| 1055 | }; |
| 1056 | |
| 1057 | let target_row = self |
| 1058 | .nodes_meta |
| 1059 | .iter() |
| 1060 | .position(|m| m.name == type_name && matches!(m.kind, "struct" | "enum" | "class")) |
| 1061 | .map(|i| i as u32); |
| 1062 | if let Some(target_row) = target_row { |
| 1063 | self.push_ref_at(target_row, &trait_name, edge_kind_index("implements").unwrap(), trait_node); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | /// extractTypeAnnotations — parameters + return_type subtrees, one |
| 1068 | /// `references` ref per type_identifier leaf not in BUILTIN_TYPES. The |
no test coverage detected