about summary refs log tree commit diff
diff options
context:
space:
mode:
authorSteve Klabnik <steve@steveklabnik.com>2016-05-11 09:27:44 -0400
committerSteve Klabnik <steve@steveklabnik.com>2016-05-11 09:27:44 -0400
commit4b8e7cb50492d0473f4f221af35c50aa469c0029 (patch)
tree4f33b644052fda5082b9134e608163ff08b35d0f
parent130e76b46a241a3d7f826e212f6db8d283c37d6f (diff)
parentde0906fe12b8663006151be7b1e32ca540710a18 (diff)
downloadrust-4b8e7cb50492d0473f4f221af35c50aa469c0029.tar.gz
rust-4b8e7cb50492d0473f4f221af35c50aa469c0029.zip
Rollup merge of #33539 - nikomatsakis:static-error, r=pnkfelix
fix DFS for region error reporting

This was causing terrible error reports, because the algorithm was incorrectly identifying the constraints.

r? @eddyb
-rw-r--r--src/librustc/infer/region_inference/mod.rs3
-rw-r--r--src/test/compile-fail/region-invariant-static-error-reporting.rs36
2 files changed, 36 insertions, 3 deletions
diff --git a/src/librustc/infer/region_inference/mod.rs b/src/librustc/infer/region_inference/mod.rs
index b889d0a9daa..9d2d52015e3 100644
--- a/src/librustc/infer/region_inference/mod.rs
+++ b/src/librustc/infer/region_inference/mod.rs
@@ -1240,9 +1240,6 @@ impl<'a, 'gcx, 'tcx> RegionVarBindings<'a, 'gcx, 'tcx> {
                    orig_node_idx,
                    node_idx);
 
-            // figure out the direction from which this node takes its
-            // values, and search for concrete regions etc in that direction
-            let dir = graph::INCOMING;
             process_edges(self, &mut state, graph, node_idx, dir);
         }
 
diff --git a/src/test/compile-fail/region-invariant-static-error-reporting.rs b/src/test/compile-fail/region-invariant-static-error-reporting.rs
new file mode 100644
index 00000000000..ac0167e08bd
--- /dev/null
+++ b/src/test/compile-fail/region-invariant-static-error-reporting.rs
@@ -0,0 +1,36 @@
+// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+// This test checks that the error messages you get for this example
+// at least mention `'a` and `'static`. The precise messages can drift
+// over time, but this test used to exhibit some pretty bogus messages
+// that were not remotely helpful.
+
+// error-pattern:cannot infer
+// error-pattern:cannot outlive the lifetime 'a
+// error-pattern:must be valid for the static lifetime
+// error-pattern:cannot infer
+// error-pattern:cannot outlive the lifetime 'a
+// error-pattern:must be valid for the static lifetime
+
+struct Invariant<'a>(Option<&'a mut &'a mut ()>);
+
+fn mk_static() -> Invariant<'static> { Invariant(None) }
+
+fn unify<'a>(x: Option<Invariant<'a>>, f: fn(Invariant<'a>)) {
+    let bad = if x.is_some() {
+        x.unwrap()
+    } else {
+        mk_static()
+    };
+    f(bad);
+}
+
+fn main() {}