]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_infer/infer/region_constraints/leak_check.rs
modify leak-check to track only outgoing edges from placeholders
[rust.git] / src / librustc_infer / infer / region_constraints / leak_check.rs
index 91c39a0e78ffb732ef8340a2cc8b4512b6983013..111a7b997a4867eaa8c6a46d12871213bd295940 100644 (file)
@@ -42,10 +42,23 @@ pub fn leak_check(
                 _ => bug!("leak_check: expected placeholder found {:?}", placeholder_region,),
             };
 
-            // Find all regions that are related to this placeholder
-            // in some way. This means any region that either outlives
-            // or is outlived by a placeholder.
-            let mut taint_set = TaintSet::new(TaintDirections::both(), placeholder_region);
+            // Find all regions that this placeholder `!p` must outlive -- i.e.,
+            // any region `r` where `!p: r` must hold. It is an error if any
+            // such region `r` is another placeholder or in a universe that
+            // can't see the placeholder. (This is actually incorrect, because
+            // we don't take into account the possibility of bounds in
+            // environment that tell us that the placeholder may be related to
+            // other regions).
+            //
+            // Note that we *don't* look for cases like `r: !p`. This is
+            // because:
+            //
+            // * If `r` is some other placeholder `!p1`, then we'll find the
+            //   error when we search the regions that `!p1` must outlive.
+            // * If `r` is a variable in some outer universe, then it can
+            //   potentially be assigned to `'static`, so this relation could
+            //   hold.
+            let mut taint_set = TaintSet::new(TaintDirections::outgoing(), placeholder_region);
             taint_set.fixed_point(
                 tcx,
                 self.undo_log.region_constraints(),