about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2017-12-06 04:56:03 -0500
committerNiko Matsakis <niko@alum.mit.edu>2017-12-15 10:27:53 -0500
commita118afe7ca742872f2064e26ddf97394d091ce3b (patch)
tree435650582744d074248496216c3158119a720c41 /src
parente9824c50edd067fefb2e4fd6f6d1a4fe739a145b (diff)
downloadrust-a118afe7ca742872f2064e26ddf97394d091ce3b.tar.gz
rust-a118afe7ca742872f2064e26ddf97394d091ce3b.zip
add a test regarding relating closure and fn generics
Turns out this works but we had no test targeting it.
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-from-trait-match.rs59
-rw-r--r--src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr60
2 files changed, 119 insertions, 0 deletions
diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.rs b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.rs
new file mode 100644
index 00000000000..d5bd4b60118
--- /dev/null
+++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.rs
@@ -0,0 +1,59 @@
+// 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 that regions which appear only in the closure's generics (in
+// this case, `'a`) are properly mapped to the creator's generics. In
+// this case, the closure constrains its type parameter `T` to outlive
+// the same `'a` for which it implements `Trait`, which can only be the `'a`
+// from the function definition.
+
+// compile-flags:-Znll -Zborrowck=mir -Zverbose
+
+#![feature(rustc_attrs)]
+#![allow(dead_code)]
+
+trait Trait<'a> {}
+
+fn establish_relationships<T, F>(value: T, closure: F)
+where
+    F: FnOnce(T),
+{
+    closure(value)
+}
+
+fn require<'a, T>(t: T)
+where
+    T: Trait<'a> + 'a,
+{
+}
+
+#[rustc_regions]
+fn supply<'a, T>(value: T)
+where
+    T: Trait<'a>,
+{
+    establish_relationships(value, |value| {
+        // This function call requires that
+        //
+        // (a) T: Trait<'a>
+        //
+        // and
+        //
+        // (b) T: 'a
+        //
+        // The latter does not hold.
+
+        require(value);
+        //~^ WARNING not reporting region error due to -Znll
+        //~| ERROR failed type test
+    });
+}
+
+fn main() {}
diff --git a/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr
new file mode 100644
index 00000000000..eb415ec8d1a
--- /dev/null
+++ b/src/test/ui/nll/closure-requirements/propagate-from-trait-match.stderr
@@ -0,0 +1,60 @@
+warning: not reporting region error due to -Znll
+  --> $DIR/propagate-from-trait-match.rs:53:9
+   |
+53 |         require(value);
+   |         ^^^^^^^
+
+note: External requirements
+  --> $DIR/propagate-from-trait-match.rs:42:36
+   |
+42 |       establish_relationships(value, |value| {
+   |  ____________________________________^
+43 | |         // This function call requires that
+44 | |         //
+45 | |         // (a) T: Trait<'a>
+...  |
+55 | |         //~| ERROR failed type test
+56 | |     });
+   | |_____^
+   |
+   = note: defining type: DefId(0/1:16 ~ propagate_from_trait_match[317d]::supply[0]::{{closure}}[0]) with closure substs [
+               '_#1r,
+               T,
+               i32,
+               extern "rust-call" fn((T,))
+           ]
+   = note: number of external vids: 2
+   = note: where T: '_#1r
+
+error: failed type test: TypeTest { generic_kind: T/#1, lower_bound: '_#3r, point: bb0[3], span: $DIR/propagate-from-trait-match.rs:42:36: 56:6, test: IsOutlivedByAnyRegionIn(['_#2r]) }
+  --> $DIR/propagate-from-trait-match.rs:42:36
+   |
+42 |       establish_relationships(value, |value| {
+   |  ____________________________________^
+43 | |         // This function call requires that
+44 | |         //
+45 | |         // (a) T: Trait<'a>
+...  |
+55 | |         //~| ERROR failed type test
+56 | |     });
+   | |_____^
+
+note: No external requirements
+  --> $DIR/propagate-from-trait-match.rs:38:1
+   |
+38 | / fn supply<'a, T>(value: T)
+39 | | where
+40 | |     T: Trait<'a>,
+41 | | {
+...  |
+56 | |     });
+57 | | }
+   | |_^
+   |
+   = note: defining type: DefId(0/0:6 ~ propagate_from_trait_match[317d]::supply[0]) with substs [
+               '_#1r,
+               T
+           ]
+
+error: aborting due to previous error
+