summaryrefslogtreecommitdiffstats
path: root/src/test/ui/regions/regions-infer-proc-static-upvar.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/regions/regions-infer-proc-static-upvar.rs')
-rw-r--r--src/test/ui/regions/regions-infer-proc-static-upvar.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/regions/regions-infer-proc-static-upvar.rs b/src/test/ui/regions/regions-infer-proc-static-upvar.rs
new file mode 100644
index 000000000..5a64aa734
--- /dev/null
+++ b/src/test/ui/regions/regions-infer-proc-static-upvar.rs
@@ -0,0 +1,24 @@
+// Test that, when a variable of type `&T` is captured inside a proc,
+// we correctly infer/require that its lifetime is 'static.
+
+fn foo<F:FnOnce()+'static>(_p: F) { }
+
+static i: isize = 3;
+
+fn capture_local() {
+ let x = 3;
+ let y = &x; //~ ERROR `x` does not live long enough
+ foo(move|| {
+ let _a = *y;
+ });
+}
+
+fn capture_static() {
+ // Legal because &i can have static lifetime:
+ let y = &i;
+ foo(move|| {
+ let _a = *y;
+ });
+}
+
+fn main() { }