rustc_borrowck/polonius/constraints.rs
1use rustc_middle::ty::RegionVid;
2use rustc_mir_dataflow::points::PointIndex;
3
4/// A localized outlives constraint reifies the CFG location where the outlives constraint holds,
5/// within the origins themselves as if they were different from point to point: from `a: b`
6/// outlives constraints to `a@p: b@p`, where `p` is the point in the CFG.
7///
8/// This models two sources of constraints:
9/// - constraints that traverse the subsets between regions at a given point, `a@p: b@p`. These
10/// depend on typeck constraints generated via assignments, calls, etc.
11/// - constraints that traverse the CFG via the same region, `a@p: a@q`, where `p` is a predecessor
12/// of `q`. These depend on the liveness of the regions at these points, as well as their
13/// variance.
14///
15/// The `source` origin at `from` flows into the `target` origin at `to`.
16///
17/// This dual of NLL's [crate::constraints::OutlivesConstraint] therefore encodes the
18/// position-dependent outlives constraints used by Polonius, to model the flow-sensitive loan
19/// propagation via reachability within a graph of localized constraints.
20#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
21pub(crate) struct LocalizedOutlivesConstraint {
22 pub source: RegionVid,
23 pub from: PointIndex,
24 pub target: RegionVid,
25 pub to: PointIndex,
26}
27
28/// A container of [LocalizedOutlivesConstraint]s that can be turned into a traversable
29/// `rustc_data_structures` graph.
30#[derive(Clone, Default, Debug)]
31pub(crate) struct LocalizedOutlivesConstraintSet {
32 pub outlives: Vec<LocalizedOutlivesConstraint>,
33}
34
35impl LocalizedOutlivesConstraintSet {
36 pub(crate) fn push(&mut self, constraint: LocalizedOutlivesConstraint) {
37 if constraint.source == constraint.target && constraint.from == constraint.to {
38 // 'a@p: 'a@p is pretty uninteresting
39 return;
40 }
41 self.outlives.push(constraint);
42 }
43}