Skip to content

Commit c9f41d4

Browse files
committed
Remove unnecessary lifetime from LeakCheck.
`LeakCheck` can own `mini_graph` and `rcc` instead of holding references to them. This requires inlining `assign_scc_value` to avoid a borrowck error, but that's fine because it has a single call site.
1 parent d7a9014 commit c9f41d4

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

compiler/rustc_infer/src/infer/region_constraints/leak_check.rs

+23-32
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
7373
/// * R: P1, R: P2, as above
7474
#[instrument(level = "debug", skip(self, tcx, only_consider_snapshot), ret)]
7575
pub fn leak_check(
76-
&mut self,
76+
self,
7777
tcx: TyCtxt<'tcx>,
7878
outer_universe: ty::UniverseIndex,
7979
max_universe: ty::UniverseIndex,
@@ -83,7 +83,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
8383
return Ok(());
8484
}
8585

86-
let mini_graph = &MiniGraph::new(tcx, self, only_consider_snapshot);
86+
let mini_graph = MiniGraph::new(tcx, &self, only_consider_snapshot);
8787

8888
let mut leak_check = LeakCheck::new(tcx, outer_universe, max_universe, mini_graph, self);
8989
leak_check.assign_placeholder_values()?;
@@ -92,11 +92,11 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
9292
}
9393
}
9494

95-
struct LeakCheck<'a, 'b, 'tcx> {
95+
struct LeakCheck<'a, 'tcx> {
9696
tcx: TyCtxt<'tcx>,
9797
outer_universe: ty::UniverseIndex,
98-
mini_graph: &'a MiniGraph<'tcx>,
99-
rcc: &'a mut RegionConstraintCollector<'b, 'tcx>,
98+
mini_graph: MiniGraph<'tcx>,
99+
rcc: RegionConstraintCollector<'a, 'tcx>,
100100

101101
// Initially, for each SCC S, stores a placeholder `P` such that `S = P`
102102
// must hold.
@@ -115,26 +115,27 @@ struct LeakCheck<'a, 'b, 'tcx> {
115115
// either the placeholder `P1` or the empty region in that same universe.
116116
//
117117
// To detect errors, we look for an SCC S where the values in
118-
// `scc_values[S]` (if any) cannot be stored into `scc_universes[S]`.
118+
// `scc_placeholders[S]` (if any) cannot be stored into `scc_universes[S]`.
119119
scc_universes: IndexVec<LeakCheckScc, SccUniverse<'tcx>>,
120120
}
121121

122-
impl<'a, 'b, 'tcx> LeakCheck<'a, 'b, 'tcx> {
122+
impl<'a, 'tcx> LeakCheck<'a, 'tcx> {
123123
fn new(
124124
tcx: TyCtxt<'tcx>,
125125
outer_universe: ty::UniverseIndex,
126126
max_universe: ty::UniverseIndex,
127-
mini_graph: &'a MiniGraph<'tcx>,
128-
rcc: &'a mut RegionConstraintCollector<'b, 'tcx>,
127+
mini_graph: MiniGraph<'tcx>,
128+
rcc: RegionConstraintCollector<'a, 'tcx>,
129129
) -> Self {
130130
let dummy_scc_universe = SccUniverse { universe: max_universe, region: None };
131+
let num_sccs = mini_graph.sccs.num_sccs();
131132
Self {
132133
tcx,
133134
outer_universe,
134135
mini_graph,
135136
rcc,
136-
scc_placeholders: IndexVec::from_elem_n(None, mini_graph.sccs.num_sccs()),
137-
scc_universes: IndexVec::from_elem_n(dummy_scc_universe, mini_graph.sccs.num_sccs()),
137+
scc_placeholders: IndexVec::from_elem_n(None, num_sccs),
138+
scc_universes: IndexVec::from_elem_n(dummy_scc_universe, num_sccs),
138139
}
139140
}
140141

@@ -156,34 +157,24 @@ impl<'a, 'b, 'tcx> LeakCheck<'a, 'b, 'tcx> {
156157
// Detect those SCCs that directly contain a placeholder
157158
if let ty::RePlaceholder(placeholder) = **region {
158159
if self.outer_universe.cannot_name(placeholder.universe) {
159-
self.assign_scc_value(scc, placeholder)?;
160+
// Update `scc_placeholders` to account for the fact that `P: S` must hold.
161+
// This may create an error.
162+
match self.scc_placeholders[scc] {
163+
Some(p) => {
164+
assert_ne!(p, placeholder);
165+
return Err(self.placeholder_error(p, placeholder));
166+
}
167+
None => {
168+
self.scc_placeholders[scc] = Some(placeholder);
169+
}
170+
}
160171
}
161172
}
162173
}
163174

164175
Ok(())
165176
}
166177

167-
// assign_scc_value(S, P): Update `scc_values` to account for the fact that `P: S` must hold.
168-
// This may create an error.
169-
fn assign_scc_value(
170-
&mut self,
171-
scc: LeakCheckScc,
172-
placeholder: ty::PlaceholderRegion,
173-
) -> RelateResult<'tcx, ()> {
174-
match self.scc_placeholders[scc] {
175-
Some(p) => {
176-
assert_ne!(p, placeholder);
177-
return Err(self.placeholder_error(p, placeholder));
178-
}
179-
None => {
180-
self.scc_placeholders[scc] = Some(placeholder);
181-
}
182-
};
183-
184-
Ok(())
185-
}
186-
187178
/// For each SCC S, iterate over each successor S1 where `S: S1`:
188179
///
189180
/// * Compute

0 commit comments

Comments
 (0)