]> git.lizzy.rs Git - rust.git/commitdiff
extract `region_value_str` helper
authorNiko Matsakis <niko@alum.mit.edu>
Mon, 23 Jul 2018 19:14:56 +0000 (22:14 +0300)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 25 Jul 2018 03:38:21 +0000 (06:38 +0300)
src/librustc_mir/borrow_check/nll/constraint_generation.rs
src/librustc_mir/borrow_check/nll/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/values.rs

index 3074782c8675053f686062982b5bb10cd20061c8..01e1dfe05fe03ff472107c013253b82d42705c40 100644 (file)
@@ -12,7 +12,7 @@
 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;
@@ -24,7 +24,6 @@
 
 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,
@@ -37,7 +36,6 @@ pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>(
         liveness_constraints,
         location_table,
         all_facts,
-        elements,
     };
 
     for (bb, data) in mir.basic_blocks().iter_enumerated() {
@@ -52,7 +50,6 @@ struct ConstraintGeneration<'cg, 'cx: 'cg, 'gcx: 'tcx, 'tcx: 'cx> {
     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> {
@@ -205,7 +202,7 @@ fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
             .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);
             });
     }
 }
index b9967c2be43d53a38af484c7cc7b507ccf523c4a..acf6f671a7f8d7dbb981b5b7dd766ab32dffcc53 100644 (file)
@@ -143,7 +143,6 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
 
     constraint_generation::generate_constraints(
         infcx,
-        &elements,
         &mut liveness_constraints,
         &mut all_facts,
         location_table,
index d3d84568804a75e3e236046307a51fec411f4148..b1bcccdf1a047173dd27aad091c1fe9696954263 100644 (file)
@@ -192,11 +192,7 @@ impl<N: Idx> RegionValues<N> {
 
     /// 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) {
@@ -252,72 +248,7 @@ impl<N: Idx> RegionValues<N> {
 
     /// 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))
     }
 }
 
@@ -372,3 +303,72 @@ fn contained_in_row<N: Idx>(
         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
+            ));
+        }
+    }
+}