]> git.lizzy.rs Git - rust.git/commitdiff
regionck: only add implied bounds from root fn to `free_region_map`
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 4 Nov 2017 09:58:57 +0000 (05:58 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 15 Nov 2017 21:49:22 +0000 (16:49 -0500)
src/librustc_typeck/check/regionck.rs

index 7f1547c0c44d306a0f9fdf2221d769e3e634ffd8..06e0e6ccdb59bc11070007df4956d430ed599760 100644 (file)
@@ -144,6 +144,14 @@ pub fn regionck_item(&self,
         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 @@ fn relate_free_regions(&mut self,
                         // 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);
+                        }
                     }
                 }
             }