Skip to content

Commit 79c5e91

Browse files
committed
introduce is_live_anywhere instead of peeking into points
and refactor misnamed `get_elements`
1 parent b4c7d1d commit 79c5e91

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/rustc_borrowck/src/region_infer/values.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,25 @@ impl<N: Idx> LivenessValues<N> {
158158
self.points.row(region).is_some_and(|r| r.contains(point))
159159
}
160160

161-
/// Returns an iterator of all the elements contained by `region`.
162-
pub(crate) fn get_elements(&self, region: N) -> impl Iterator<Item = Location> + '_ {
161+
/// Returns whether `region` is marked live at any location.
162+
pub(crate) fn is_live_anywhere(&self, region: N) -> bool {
163+
self.live_points(region).next().is_some()
164+
}
165+
166+
/// Returns an iterator of all the points where `region` is live.
167+
fn live_points(&self, region: N) -> impl Iterator<Item = PointIndex> + '_ {
163168
self.points
164169
.row(region)
165170
.into_iter()
166171
.flat_map(|set| set.iter())
167-
.take_while(move |&p| self.elements.point_in_range(p))
168-
.map(move |p| self.elements.to_location(p))
172+
.take_while(|&p| self.elements.point_in_range(p))
169173
}
170174

171175
/// Returns a "pretty" string value of the region. Meant for debugging.
172176
pub(crate) fn region_value_str(&self, region: N) -> String {
173-
region_value_str(self.get_elements(region).map(RegionElement::Location))
177+
region_value_str(
178+
self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))),
179+
)
174180
}
175181

176182
#[inline]

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
596596
// If the region is live at at least one location in the promoted MIR,
597597
// then add a liveness constraint to the main MIR for this region
598598
// at the location provided as an argument to this method
599-
if liveness_constraints.get_elements(region).next().is_some() {
599+
if liveness_constraints.is_live_anywhere(region) {
600600
self.cx
601601
.borrowck_context
602602
.constraints

0 commit comments

Comments
 (0)