Repository: rust-lang/rust
File: compiler/rustc_infer/src/infer/lexical_region_resolve/indexed_edges.rs (Rust)

Code before:

        for pair @ (c, _) in data.constraints.iter() {
            let mut push_in_edge = || out_edges[c.sub.as_var()].push(pair);
            // Only push out-edges if the source is a var.
            match c.kind {
                ConstraintKind::VarSubVar => push_in_edge(),
                ConstraintKind::RegSubVar => {}
                ConstraintKind::VarSubReg => push_in_edge(),
                ConstraintKind::RegSubReg => {}
            }
        }

        // Index in-edges in reverse order, to match what current tests expect.
        // (It's unclear whether this is important or not.)
        for pair @ (c, _) in data.constraints.iter().rev() {
            let mut push_out_edge = || in_edges[c.sup.as_var()].push(pair);
            // Only push in-edges if the target is a var.
            match c.kind {
                ConstraintKind::VarSubVar => push_out_edge(),
                ConstraintKind::RegSubVar => push_out_edge(),
                ConstraintKind::VarSubReg => {}
                ConstraintKind::RegSubReg => {}
            }
        }

        Self { out_edges, in_edges }
    }

    /// Returns either the out-edges or in-edges of the specified region var,
    /// as selected by `dir`.
    pub(crate) fn adjacent_edges(
        &self,
        region_vid: RegionVid,
        dir: EdgeDirection,
    ) -> &[&'data ConstraintPair<'tcx>] {
        let edges = match dir {
            EdgeDirection::Out => &self.out_edges,
            EdgeDirection::In => &self.in_edges,
        };
        edges[region_vid].as_slice()
    }
}


Review comment (suggestion):
```suggestion
        IndexedConstraintEdges { out_edges, in_edges }
```
Could you avoid `Self` in non-generic code? It's harder to find anything if it's used.

Code after:
        let mut out_edges = IndexVec::from_fn_n(|_| vec![], num_vars);
        let mut in_edges = IndexVec::from_fn_n(|_| vec![], num_vars);

        for pair @ (c, _) in &data.constraints {
            // Only push a var out-edge for `VarSub...` constraints.
            match c.kind {
                ConstraintKind::VarSubVar | ConstraintKind::VarSubReg => {
                    out_edges[c.sub.as_var()].push(pair)
                }
                ConstraintKind::RegSubVar | ConstraintKind::RegSubReg => {}
            }
        }

        // Index in-edges in reverse order, to match what current tests expect.
        // (It's unclear whether this is important or not.)
        for pair @ (c, _) in data.constraints.iter().rev() {
            // Only push a var in-edge for `...SubVar` constraints.
            match c.kind {
                ConstraintKind::VarSubVar | ConstraintKind::RegSubVar => {
                    in_edges[c.sup.as_var()].push(pair)
                }
                ConstraintKind::VarSubReg | ConstraintKind::RegSubReg => {}
            }
        }

        IndexedConstraintEdges { out_edges, in_edges }
    }

    /// Returns either the out-edges or in-edges of the specified region var,
    /// as selected by `dir`.
    pub(super) fn adjacent_edges(
        &self,
        region_vid: RegionVid,
        dir: EdgeDirection,
    ) -> &[&'data ConstraintPair<'tcx>] {
        let edges = match dir {
            EdgeDirection::Out => &self.out_edges,
            EdgeDirection::In => &self.in_edges,
        };
        &edges[region_vid]
    }
}