use borrow_check::location::LocationTable;
use borrow_check::nll::ToRegionVid;
use borrow_check::nll::facts::AllFacts;
-use borrow_check::nll::region_infer::values::{RegionValueElements, RegionValues};
+use borrow_check::nll::region_infer::values::RegionValues;
use rustc::infer::InferCtxt;
use rustc::mir::visit::TyContext;
use rustc::mir::visit::Visitor;
pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>(
infcx: &InferCtxt<'cx, 'gcx, 'tcx>,
- elements: &RegionValueElements,
liveness_constraints: &mut RegionValues<RegionVid>,
all_facts: &mut Option<AllFacts>,
location_table: &LocationTable,
liveness_constraints,
location_table,
all_facts,
- elements,
};
for (bb, data) in mir.basic_blocks().iter_enumerated() {
location_table: &'cg LocationTable,
liveness_constraints: &'cg mut RegionValues<RegionVid>,
borrow_set: &'cg BorrowSet<'tcx>,
- elements: &'cg RegionValueElements,
}
impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx, 'tcx> {
.tcx
.for_each_free_region(&live_ty, |live_region| {
let vid = live_region.to_region_vid();
- self.liveness_constraints.add_element(&self.elements, vid, location);
+ self.liveness_constraints.add_element(vid, location);
});
}
}
/// True if `sup_region` contains all the CFG points that
/// `sub_region` contains. Ignores universal regions.
- crate fn contains_points(
- &self,
- sup_region: N,
- sub_region: N,
- ) -> bool {
+ crate fn contains_points(&self, sup_region: N, sub_region: N) -> bool {
// This could be done faster by comparing the bitsets. But I
// am lazy.
if let Some(sub_row) = self.points.row(sub_region) {
/// Returns a "pretty" string value of the region. Meant for debugging.
crate fn region_value_str(&self, r: N) -> String {
- let mut result = String::new();
- result.push_str("{");
-
- // Set to Some(l1, l2) when we have observed all the locations
- // from l1..=l2 (inclusive) but not yet printed them. This
- // gets extended if we then see l3 where l3 is the successor
- // to l2.
- let mut open_location: Option<(Location, Location)> = None;
-
- let mut sep = "";
- let mut push_sep = |s: &mut String| {
- s.push_str(sep);
- sep = ", ";
- };
-
- for element in self.elements_contained_in(r) {
- match element {
- RegionElement::Location(l) => {
- if let Some((location1, location2)) = open_location {
- if location2.block == l.block
- && location2.statement_index == l.statement_index - 1
- {
- open_location = Some((location1, l));
- continue;
- }
-
- push_sep(&mut result);
- Self::push_location_range(&mut result, location1, location2);
- }
-
- open_location = Some((l, l));
- }
-
- RegionElement::RootUniversalRegion(fr) => {
- if let Some((location1, location2)) = open_location {
- push_sep(&mut result);
- Self::push_location_range(&mut result, location1, location2);
- open_location = None;
- }
-
- push_sep(&mut result);
- result.push_str(&format!("{:?}", fr));
- }
- }
- }
-
- if let Some((location1, location2)) = open_location {
- push_sep(&mut result);
- Self::push_location_range(&mut result, location1, location2);
- }
-
- result.push_str("}");
-
- result
- }
-
- fn push_location_range(str: &mut String, location1: Location, location2: Location) {
- if location1 == location2 {
- str.push_str(&format!("{:?}", location1));
- } else {
- assert_eq!(location1.block, location2.block);
- str.push_str(&format!(
- "{:?}[{}..={}]",
- location1.block, location1.statement_index, location2.statement_index
- ));
- }
+ region_value_str(self.elements_contained_in(r))
}
}
values.free_regions.contains(row, self)
}
}
+
+crate fn region_value_str(elements: impl IntoIterator<Item = RegionElement>) -> String {
+ let mut result = String::new();
+ result.push_str("{");
+
+ // Set to Some(l1, l2) when we have observed all the locations
+ // from l1..=l2 (inclusive) but not yet printed them. This
+ // gets extended if we then see l3 where l3 is the successor
+ // to l2.
+ let mut open_location: Option<(Location, Location)> = None;
+
+ let mut sep = "";
+ let mut push_sep = |s: &mut String| {
+ s.push_str(sep);
+ sep = ", ";
+ };
+
+ for element in elements {
+ match element {
+ RegionElement::Location(l) => {
+ if let Some((location1, location2)) = open_location {
+ if location2.block == l.block
+ && location2.statement_index == l.statement_index - 1
+ {
+ open_location = Some((location1, l));
+ continue;
+ }
+
+ push_sep(&mut result);
+ push_location_range(&mut result, location1, location2);
+ }
+
+ open_location = Some((l, l));
+ }
+
+ RegionElement::RootUniversalRegion(fr) => {
+ if let Some((location1, location2)) = open_location {
+ push_sep(&mut result);
+ push_location_range(&mut result, location1, location2);
+ open_location = None;
+ }
+
+ push_sep(&mut result);
+ result.push_str(&format!("{:?}", fr));
+ }
+ }
+ }
+
+ if let Some((location1, location2)) = open_location {
+ push_sep(&mut result);
+ push_location_range(&mut result, location1, location2);
+ }
+
+ result.push_str("}");
+
+ return result;
+
+ fn push_location_range(str: &mut String, location1: Location, location2: Location) {
+ if location1 == location2 {
+ str.push_str(&format!("{:?}", location1));
+ } else {
+ assert_eq!(location1.block, location2.block);
+ str.push_str(&format!(
+ "{:?}[{}..={}]",
+ location1.block, location1.statement_index, location2.statement_index
+ ));
+ }
+ }
+}