summaryrefslogtreecommitdiffstats
path: root/tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs')
-rw-r--r--tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs b/tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs
new file mode 100644
index 000000000..2d219643f
--- /dev/null
+++ b/tests/ui/unboxed-closures/unboxed-closures-move-some-upvars-in-by-ref-closure.rs
@@ -0,0 +1,23 @@
+// run-pass
+// Test that in a by-ref once closure we move some variables even as
+// we capture others by mutable reference.
+
+fn call<F>(f: F) where F : FnOnce() {
+ f();
+}
+
+fn main() {
+ let mut x = vec![format!("Hello")];
+ let y = vec![format!("World")];
+ call(|| {
+ // Here: `x` must be captured with a mutable reference in
+ // order for us to append on it, and `y` must be captured by
+ // value.
+ for item in y {
+ x.push(item);
+ }
+ });
+ assert_eq!(x.len(), 2);
+ assert_eq!(&*x[0], "Hello");
+ assert_eq!(&*x[1], "World");
+}