]> git.lizzy.rs Git - rust.git/commitdiff
make a free fn for creating the URR
authorNiko Matsakis <niko@alum.mit.edu>
Thu, 26 Jul 2018 11:49:45 +0000 (14:49 +0300)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Tue, 31 Jul 2018 00:31:41 +0000 (02:31 +0200)
src/librustc_mir/borrow_check/nll/type_check/free_region_relations.rs
src/librustc_mir/borrow_check/nll/type_check/mod.rs

index d2850f8f32443e651a4256efb760f0ed3d356784..a539bf5f3aa96d75ebb973e8f30ff22fc1fa9766 100644 (file)
@@ -9,11 +9,11 @@
 // except according to those terms.
 
 use borrow_check::location::LocationTable;
-use borrow_check::nll::ToRegionVid;
 use borrow_check::nll::facts::AllFacts;
 use borrow_check::nll::type_check::constraint_conversion;
 use borrow_check::nll::type_check::{Locations, MirTypeckRegionConstraints};
 use borrow_check::nll::universal_regions::UniversalRegions;
+use borrow_check::nll::ToRegionVid;
 use rustc::hir::def_id::DefId;
 use rustc::infer::outlives::free_region_map::FreeRegionRelations;
 use rustc::infer::region_constraints::GenericKind;
     inverse_outlives: TransitiveRelation<RegionVid>,
 }
 
-impl UniversalRegionRelations<'tcx> {
-    crate fn create(
-        infcx: &InferCtxt<'_, '_, 'tcx>,
-        mir_def_id: DefId,
-        param_env: ty::ParamEnv<'tcx>,
-        location_table: &LocationTable,
-        implicit_region_bound: Option<ty::Region<'tcx>>,
-        universal_regions: &Rc<UniversalRegions<'tcx>>,
-        constraints: &mut MirTypeckRegionConstraints<'tcx>,
-        all_facts: &mut Option<AllFacts>,
-    ) -> Self {
-        let mir_node_id = infcx.tcx.hir.as_local_node_id(mir_def_id).unwrap();
-        UniversalRegionRelationsBuilder {
-            infcx,
-            mir_def_id,
-            mir_node_id,
-            param_env,
-            implicit_region_bound,
-            constraints,
-            location_table,
-            all_facts,
+crate fn create(
+    infcx: &InferCtxt<'_, '_, 'tcx>,
+    mir_def_id: DefId,
+    param_env: ty::ParamEnv<'tcx>,
+    location_table: &LocationTable,
+    implicit_region_bound: Option<ty::Region<'tcx>>,
+    universal_regions: &Rc<UniversalRegions<'tcx>>,
+    constraints: &mut MirTypeckRegionConstraints<'tcx>,
+    all_facts: &mut Option<AllFacts>,
+) -> Rc<UniversalRegionRelations<'tcx>> {
+    let mir_node_id = infcx.tcx.hir.as_local_node_id(mir_def_id).unwrap();
+    UniversalRegionRelationsBuilder {
+        infcx,
+        mir_def_id,
+        mir_node_id,
+        param_env,
+        implicit_region_bound,
+        constraints,
+        location_table,
+        all_facts,
+        universal_regions: universal_regions.clone(),
+        relations: UniversalRegionRelations {
             universal_regions: universal_regions.clone(),
-            relations: UniversalRegionRelations {
-                universal_regions: universal_regions.clone(),
-                region_bound_pairs: Vec::new(),
-                outlives: TransitiveRelation::new(),
-                inverse_outlives: TransitiveRelation::new(),
-            },
-        }.create()
-    }
+            region_bound_pairs: Vec::new(),
+            outlives: TransitiveRelation::new(),
+            inverse_outlives: TransitiveRelation::new(),
+        },
+    }.create()
+}
 
+impl UniversalRegionRelations<'tcx> {
     /// Records in the `outlives_relation` (and
     /// `inverse_outlives_relation`) that `fr_a: fr_b`. Invoked by the
     /// builder below.
@@ -212,7 +212,7 @@ struct UniversalRegionRelationsBuilder<'this, 'gcx: 'tcx, 'tcx: 'this> {
 }
 
 impl UniversalRegionRelationsBuilder<'cx, 'gcx, 'tcx> {
-    crate fn create(mut self) -> UniversalRegionRelations<'tcx> {
+    crate fn create(mut self) -> Rc<UniversalRegionRelations<'tcx>> {
         let unnormalized_input_output_tys = self
             .universal_regions
             .unnormalized_input_tys
@@ -277,7 +277,7 @@ impl UniversalRegionRelationsBuilder<'cx, 'gcx, 'tcx> {
             ).convert_all(&data);
         }
 
-        self.relations
+        Rc::new(self.relations)
     }
 
     /// Update the type of a single local, which should represent
index 15deb5fb2f4984ca966a97cc0e6ddcbb8d205a63..d4a4e17849c8e1af063f49f3bf8c3cdb0951279c 100644 (file)
@@ -132,17 +132,16 @@ pub(crate) fn type_check<'gcx, 'tcx>(
         type_tests: Vec::default(),
     };
 
-    let universal_region_relations =
-        Rc::new(free_region_relations::UniversalRegionRelations::create(
-            infcx,
-            mir_def_id,
-            param_env,
-            location_table,
-            Some(implicit_region_bound),
-            universal_regions,
-            &mut constraints,
-            all_facts,
-        ));
+    let universal_region_relations = free_region_relations::create(
+        infcx,
+        mir_def_id,
+        param_env,
+        location_table,
+        Some(implicit_region_bound),
+        universal_regions,
+        &mut constraints,
+        all_facts,
+    );
 
     {
         let mut borrowck_context = BorrowCheckContext {