]> git.lizzy.rs Git - rust.git/commitdiff
test approximations of the "shorter side" that resort to `'static`
authorNiko Matsakis <niko@alum.mit.edu>
Wed, 6 Dec 2017 21:25:10 +0000 (16:25 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 7 Dec 2017 10:28:03 +0000 (05:28 -0500)
This includes the additional case suggested by arielb1.

src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs [new file with mode: 0644]
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr [new file with mode: 0644]
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs [new file with mode: 0644]
src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr [new file with mode: 0644]
src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs [deleted file]
src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr [deleted file]

diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs
new file mode 100644 (file)
index 0000000..f776ddc
--- /dev/null
@@ -0,0 +1,51 @@
+// Copyright 2016 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.
+
+// Test a case where we are trying to prove `'x: 'y` and are forced to
+// approximate the shorter end-point (`'y`) to with `'static`. This is
+// because `'y` is higher-ranked but we know of no relations to other
+// regions. Note that `'static` shows up in the stderr output as `'0`.
+//
+// FIXME(#45827) Because of shortcomings in the MIR type checker,
+// these errors are not (yet) reported.
+
+// compile-flags:-Znll -Zborrowck=mir -Zverbose
+
+#![feature(rustc_attrs)]
+
+use std::cell::Cell;
+
+// Callee knows that:
+//
+// 'x: 'a
+//
+// so the only way we can ensure that `'x: 'y` is to show that
+// `'a: 'static`.
+fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
+where
+    F: for<'x, 'y> FnMut(
+        &Cell<&'a &'x u32>, // shows that 'x: 'a
+        &Cell<&'x u32>,
+        &Cell<&'y u32>,
+    ),
+{
+}
+
+fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
+
+#[rustc_regions]
+fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
+    establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
+        // Only works if 'x: 'y:
+        demand_y(x, y, x.get())
+    });
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr
new file mode 100644 (file)
index 0000000..8d1b9a9
--- /dev/null
@@ -0,0 +1,36 @@
+warning: not reporting region error due to -Znll
+  --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:47:9
+   |
+47 |         demand_y(x, y, x.get())
+   |         ^^^^^^^^^^^^^^^^^^^^^^^
+
+note: External requirements
+  --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
+   |
+45 |       establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
+   |  _______________________________________________^
+46 | |         // Only works if 'x: 'y:
+47 | |         demand_y(x, y, x.get())
+48 | |     });
+   | |_____^
+   |
+   = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
+               i16,
+               for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) u32>))
+           ]
+   = note: number of external vids: 2
+   = note: where '_#1r: '_#0r
+
+note: No external requirements
+  --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
+   |
+44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
+45 | |     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
+46 | |         // Only works if 'x: 'y:
+47 | |         demand_y(x, y, x.get())
+48 | |     });
+49 | | }
+   | |_^
+   |
+   = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
+
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs
new file mode 100644 (file)
index 0000000..54b501c
--- /dev/null
@@ -0,0 +1,54 @@
+// Copyright 2016 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.
+
+// Test a case where we are trying to prove `'x: 'y` and are forced to
+// approximate the shorter end-point (`'y`) to with `'static`. This is
+// because `'y` is higher-ranked but we know of only irrelevant
+// relations to other regions. Note that `'static` shows up in the
+// stderr output as `'0`.
+//
+// FIXME(#45827) Because of shortcomings in the MIR type checker,
+// these errors are not (yet) reported.
+
+// compile-flags:-Znll -Zborrowck=mir -Zverbose
+
+#![feature(rustc_attrs)]
+
+use std::cell::Cell;
+
+// Callee knows that:
+//
+// 'x: 'a
+// 'y: 'b
+//
+// so the only way we can ensure that `'x: 'y` is to show that
+// `'a: 'static`.
+fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
+where
+    F: for<'x, 'y> FnMut(
+        &Cell<&'a &'x u32>, // shows that 'x: 'a
+        &Cell<&'b &'y u32>, // shows that 'y: 'b
+        &Cell<&'x u32>,
+        &Cell<&'y u32>,
+    ),
+{
+}
+
+fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
+
+#[rustc_regions]
+fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
+    establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
+        // Only works if 'x: 'y:
+        demand_y(x, y, x.get())
+    });
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr
new file mode 100644 (file)
index 0000000..9d318a6
--- /dev/null
@@ -0,0 +1,36 @@
+warning: not reporting region error due to -Znll
+  --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:50:9
+   |
+50 |         demand_y(x, y, x.get())
+   |         ^^^^^^^^^^^^^^^^^^^^^^^
+
+note: External requirements
+  --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
+   |
+48 |       establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
+   |  _______________________________________________^
+49 | |         // Only works if 'x: 'y:
+50 | |         demand_y(x, y, x.get())
+51 | |     });
+   | |_____^
+   |
+   = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
+               i16,
+               for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&'_#2r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
+           ]
+   = note: number of external vids: 3
+   = note: where '_#1r: '_#0r
+
+note: No external requirements
+  --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
+   |
+47 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
+48 | |     establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
+49 | |         // Only works if 'x: 'y:
+50 | |         demand_y(x, y, x.get())
+51 | |     });
+52 | | }
+   | |_^
+   |
+   = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
+
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs
deleted file mode 100644 (file)
index 5e669b3..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-// Copyright 2016 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.
-
-// Test a case where we are forced to approximate one end-point with
-// `'static`. Note that `'static` shows up in the stderr output as `'0`.
-
-// compile-flags:-Znll -Zborrowck=mir -Zverbose
-
-#![feature(rustc_attrs)]
-
-use std::cell::Cell;
-
-// Callee knows that:
-//
-// 'x: 'a
-//
-// so the only way we can ensure that `'x: 'y` is to show that
-// `'a: 'static`.
-fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
-where
-    F: for<'x, 'y> FnMut(
-        &Cell<&'a &'x u32>, // shows that 'x: 'a
-        &Cell<&'x u32>,
-        &Cell<&'y u32>,
-    ),
-{
-}
-
-fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
-
-#[rustc_regions]
-fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
-    establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-        // Only works if 'x: 'y:
-        demand_y(x, y, x.get())
-    });
-}
-
-fn main() {}
diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr
deleted file mode 100644 (file)
index c23d2a8..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-warning: not reporting region error due to -Znll
-  --> $DIR/propagate-approximated-to-static.rs:42:9
-   |
-42 |         demand_y(x, y, x.get())
-   |         ^^^^^^^^^^^^^^^^^^^^^^^
-
-note: External requirements
-  --> $DIR/propagate-approximated-to-static.rs:40:47
-   |
-40 |       establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-   |  _______________________________________________^
-41 | |         // Only works if 'x: 'y:
-42 | |         demand_y(x, y, x.get())
-43 | |     });
-   | |_____^
-   |
-   = note: defining type: DefId(0/1:18 ~ propagate_approximated_to_static[317d]::supply[0]::{{closure}}[0]) with closure substs [
-               i16,
-               for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) u32>))
-           ]
-   = note: number of external vids: 2
-   = note: where '_#1r: '_#0r
-
-note: No external requirements
-  --> $DIR/propagate-approximated-to-static.rs:39:1
-   |
-39 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
-40 | |     establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
-41 | |         // Only works if 'x: 'y:
-42 | |         demand_y(x, y, x.get())
-43 | |     });
-44 | | }
-   | |_^
-   |
-   = note: defining type: DefId(0/0:6 ~ propagate_approximated_to_static[317d]::supply[0]) with substs []
-