The candidates, by index, that get one reference per scope instead of one per function, each with the id of the scope it sits in: names a function uses at least twice and binds itself. Only those candidates' positions are read from the tree. Mirrors goScopedFnRefScopes.
(cands: &[Cand<'t>], node_ids: &[String], src: &str)
| 1642 | /// function uses at least twice and binds itself. Only those candidates' |
| 1643 | /// positions are read from the tree. Mirrors goScopedFnRefScopes. |
| 1644 | fn go_scoped_fn_ref_scopes<'t>(cands: &[Cand<'t>], node_ids: &[String], src: &str) -> HashMap<usize, usize> { |
| 1645 | let mut groups: HashMap<(&str, &str), Vec<usize>> = HashMap::new(); |
| 1646 | for (i, c) in cands.iter().enumerate() { |
| 1647 | if c.name.contains('.') { |
| 1648 | continue; |
| 1649 | } |
| 1650 | groups.entry((node_ids[c.from as usize].as_str(), c.name.as_str())).or_default().push(i); |
| 1651 | } |
| 1652 | let mut sites: Vec<(usize, usize, Node<'t>)> = Vec::new(); |
| 1653 | let mut units: Vec<Node<'t>> = Vec::new(); |
| 1654 | let mut unit_ids: HashSet<usize> = HashSet::new(); |
| 1655 | let mut names: HashSet<&str> = HashSet::new(); |
| 1656 | for members in groups.values() { |
| 1657 | if members.len() < 2 { |
| 1658 | continue; |
| 1659 | } |
| 1660 | for &i in members { |
| 1661 | let (scope, unit) = go_fn_ref_site(cands[i].node); |
| 1662 | let Some(unit) = unit else { continue }; |
| 1663 | sites.push((i, scope, unit)); |
| 1664 | if unit_ids.insert(unit.id()) { |
| 1665 | units.push(unit); |
| 1666 | } |
| 1667 | names.insert(cands[i].name.as_str()); |
| 1668 | } |
| 1669 | } |
| 1670 | let mut out: HashMap<usize, usize> = HashMap::new(); |
| 1671 | if units.is_empty() { |
| 1672 | return out; |
| 1673 | } |
| 1674 | let bound = go_local_bindings(&units, &names, src); |
| 1675 | for (i, scope, unit) in sites { |
| 1676 | if bound.contains(&(unit.id(), cands[i].name.clone())) { |
| 1677 | out.insert(i, scope); |
| 1678 | } |
| 1679 | } |
| 1680 | out |
| 1681 | } |
no test coverage detected