about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-08-14 03:46:22 +0000
committerbors <bors@rust-lang.org>2014-08-14 03:46:22 +0000
commit9d45d63d0d18f21f74c8a2a4e5367a785932f64e (patch)
treeb87ab6a2dd1256c5068314d0773dcf485c58a624 /src/test
parentaa98b25c4f0c10729dff37c699904ad57b8fbda8 (diff)
parenta63003fe1aac487d3c0c527c4c984375c998de99 (diff)
downloadrust-9d45d63d0d18f21f74c8a2a4e5367a785932f64e.tar.gz
rust-9d45d63d0d18f21f74c8a2a4e5367a785932f64e.zip
auto merge of #15929 : pcwalton/rust/by-ref-closures, r=alexcrichton
by-reference upvars.

This partially implements RFC 38. A snapshot will be needed to turn this
on, because stage0 cannot yet parse the keyword.

Part of #12831.

r? @alexcrichton
Diffstat (limited to 'src/test')
-rw-r--r--src/test/run-pass/capture-clauses-boxed-closures.rs23
-rw-r--r--src/test/run-pass/capture-clauses-unboxed-closures.rs29
2 files changed, 52 insertions, 0 deletions
diff --git a/src/test/run-pass/capture-clauses-boxed-closures.rs b/src/test/run-pass/capture-clauses-boxed-closures.rs
new file mode 100644
index 00000000000..c88b44925d0
--- /dev/null
+++ b/src/test/run-pass/capture-clauses-boxed-closures.rs
@@ -0,0 +1,23 @@
+// Copyright 2014 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.
+
+fn each<T>(x: &[T], f: |&T|) {
+    for val in x.iter() {
+        f(val)
+    }
+}
+
+fn main() {
+    let mut sum = 0u;
+    let elems = [ 1u, 2, 3, 4, 5 ];
+    each(elems, ref |val| sum += *val);
+    assert_eq!(sum, 15);
+}
+
diff --git a/src/test/run-pass/capture-clauses-unboxed-closures.rs b/src/test/run-pass/capture-clauses-unboxed-closures.rs
new file mode 100644
index 00000000000..99e6d6e7a4f
--- /dev/null
+++ b/src/test/run-pass/capture-clauses-unboxed-closures.rs
@@ -0,0 +1,29 @@
+// Copyright 2014 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.
+
+// ignore-test
+//
+// This is ignored because it depends on #16122.
+
+#![feature(overloaded_calls, unboxed_closures)]
+
+fn each<'a,T,F:|&mut: &'a T|>(x: &'a [T], mut f: F) {
+    for val in x.iter() {
+        f(val)
+    }
+}
+
+fn main() {
+    let mut sum = 0u;
+    let elems = [ 1u, 2, 3, 4, 5 ];
+    each(elems, ref |&mut: val: &uint| sum += *val);
+    assert_eq!(sum, 15);
+}
+