about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-11-04 05:58:57 -0400
committerNiko Matsakis <niko@alum.mit.edu>2017-11-15 16:49:22 -0500
commitb587c1a024f6946ee31186447564a2e5cb4e7602 (patch)
tree83e703141cd204b1db89907f60c5c6670fbb0754 /src
parent3cc44a569ded1484b0ab4fcc5b8cfd545ea3a4b5 (diff)
downloadrust-b587c1a024f6946ee31186447564a2e5cb4e7602.tar.gz
rust-b587c1a024f6946ee31186447564a2e5cb4e7602.zip
regionck: only add implied bounds from root fn to `free_region_map`
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/regionck.rs19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs
index 7f1547c0c44..06e0e6ccdb5 100644
--- a/src/librustc_typeck/check/regionck.rs
+++ b/src/librustc_typeck/check/regionck.rs
@@ -144,6 +144,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
         rcx.resolve_regions_and_report_errors();
     }
 
+    /// Region check a function body. Not invoked on closures, but
+    /// only on the "root" fn item (in which closures may be
+    /// embedded). Walks the function body and adds various add'l
+    /// constraints that are needed for region inference. This is
+    /// separated both to isolate "pure" region constraints from the
+    /// rest of type check and because sometimes we need type
+    /// inference to have completed before we can determine which
+    /// constraints to add.
     pub fn regionck_fn(&self,
                        fn_id: ast::NodeId,
                        body: &'gcx hir::Body) {
@@ -414,7 +422,16 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> {
                         // system to be more general and to make use
                         // of *every* relationship that arises here,
                         // but presently we do not.)
-                        self.free_region_map.relate_regions(r_a, r_b);
+                        if body_id == self.fcx.body_id {
+                            // Only modify `free_region_map` if these
+                            // are parameters from the root
+                            // function. That's because this data
+                            // struture is shared across all functions
+                            // and hence we don't want to take implied
+                            // bounds from one closure and use them
+                            // outside.
+                            self.free_region_map.relate_regions(r_a, r_b);
+                        }
                     }
                 }
             }