diff --git a/compiler/rustc_borrowck/src/region_infer/values.rs b/compiler/rustc_borrowck/src/region_infer/values.rs index 502e884b531d2..e005e4d63b6e3 100644 --- a/compiler/rustc_borrowck/src/region_infer/values.rs +++ b/compiler/rustc_borrowck/src/region_infer/values.rs @@ -158,19 +158,25 @@ impl LivenessValues { self.points.row(region).is_some_and(|r| r.contains(point)) } - /// Returns an iterator of all the elements contained by `region`. - pub(crate) fn get_elements(&self, region: N) -> impl Iterator + '_ { + /// Returns whether `region` is marked live at any location. + pub(crate) fn is_live_anywhere(&self, region: N) -> bool { + self.live_points(region).next().is_some() + } + + /// Returns an iterator of all the points where `region` is live. + fn live_points(&self, region: N) -> impl Iterator + '_ { self.points .row(region) .into_iter() .flat_map(|set| set.iter()) .take_while(move |&p| self.elements.point_in_range(p)) - .map(move |p| self.elements.to_location(p)) } /// Returns a "pretty" string value of the region. Meant for debugging. pub(crate) fn region_value_str(&self, region: N) -> String { - region_value_str(self.get_elements(region).map(RegionElement::Location)) + region_value_str( + self.live_points(region).map(|p| RegionElement::Location(self.elements.to_location(p))), + ) } #[inline] diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index f00e41e08863a..e23f633bea2b6 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -596,7 +596,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> { // If the region is live at at least one location in the promoted MIR, // then add a liveness constraint to the main MIR for this region // at the location provided as an argument to this method - if liveness_constraints.get_elements(region).next().is_some() { + if liveness_constraints.is_live_anywhere(region) { self.cx .borrowck_context .constraints