about summary refs log tree commit diff
path: root/src/test/ui/moves
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 01:33:01 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-27 18:56:16 +0300
commit9be35f82c1abf2ecbab489bca9eca138ea648312 (patch)
tree69888506e34af447d9748c0d542de3ba1dd76210 /src/test/ui/moves
parentca9faa52f5ada0054b1fa27d97aedf448afb059b (diff)
downloadrust-9be35f82c1abf2ecbab489bca9eca138ea648312.tar.gz
rust-9be35f82c1abf2ecbab489bca9eca138ea648312.zip
tests: Move run-pass tests without naming conflicts to ui
Diffstat (limited to 'src/test/ui/moves')
-rw-r--r--src/test/ui/moves/move-1-unique.rs25
-rw-r--r--src/test/ui/moves/move-2-unique.rs11
-rw-r--r--src/test/ui/moves/move-2.rs7
-rw-r--r--src/test/ui/moves/move-3-unique.rs25
-rw-r--r--src/test/ui/moves/move-4-unique.rs19
-rw-r--r--src/test/ui/moves/move-4.rs19
-rw-r--r--src/test/ui/moves/move-arg-2-unique.rs13
-rw-r--r--src/test/ui/moves/move-arg-2.rs13
-rw-r--r--src/test/ui/moves/move-arg.rs5
-rw-r--r--src/test/ui/moves/move-nullary-fn.rs13
-rw-r--r--src/test/ui/moves/move-out-of-field.rs27
-rw-r--r--src/test/ui/moves/move-scalar.rs10
-rw-r--r--src/test/ui/moves/moves-based-on-type-capture-clause.rs12
13 files changed, 199 insertions, 0 deletions
diff --git a/src/test/ui/moves/move-1-unique.rs b/src/test/ui/moves/move-1-unique.rs
new file mode 100644
index 00000000000..48baead074a
--- /dev/null
+++ b/src/test/ui/moves/move-1-unique.rs
@@ -0,0 +1,25 @@
+// run-pass
+#![allow(unused_mut)]
+#![feature(box_syntax)]
+
+#[derive(Clone)]
+struct Triple {
+    x: isize,
+    y: isize,
+    z: isize,
+}
+
+fn test(x: bool, foo: Box<Triple>) -> isize {
+    let bar = foo;
+    let mut y: Box<Triple>;
+    if x { y = bar; } else { y = box Triple{x: 4, y: 5, z: 6}; }
+    return y.y;
+}
+
+pub fn main() {
+    let x: Box<_> = box Triple{x: 1, y: 2, z: 3};
+    assert_eq!(test(true, x.clone()), 2);
+    assert_eq!(test(true, x.clone()), 2);
+    assert_eq!(test(true, x.clone()), 2);
+    assert_eq!(test(false, x), 5);
+}
diff --git a/src/test/ui/moves/move-2-unique.rs b/src/test/ui/moves/move-2-unique.rs
new file mode 100644
index 00000000000..910a88c102f
--- /dev/null
+++ b/src/test/ui/moves/move-2-unique.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(dead_code)]
+#![feature(box_syntax)]
+
+struct X { x: isize, y: isize, z: isize }
+
+pub fn main() {
+    let x: Box<_> = box X{x: 1, y: 2, z: 3};
+    let y = x;
+    assert_eq!(y.y, 2);
+}
diff --git a/src/test/ui/moves/move-2.rs b/src/test/ui/moves/move-2.rs
new file mode 100644
index 00000000000..4ad53e96e50
--- /dev/null
+++ b/src/test/ui/moves/move-2.rs
@@ -0,0 +1,7 @@
+// run-pass
+#![allow(dead_code)]
+#![feature(box_syntax)]
+
+struct X { x: isize, y: isize, z: isize }
+
+pub fn main() { let x: Box<_> = box X {x: 1, y: 2, z: 3}; let y = x; assert_eq!(y.y, 2); }
diff --git a/src/test/ui/moves/move-3-unique.rs b/src/test/ui/moves/move-3-unique.rs
new file mode 100644
index 00000000000..55b10e057d8
--- /dev/null
+++ b/src/test/ui/moves/move-3-unique.rs
@@ -0,0 +1,25 @@
+// run-pass
+#![allow(unused_mut)]
+#![feature(box_syntax)]
+
+#[derive(Clone)]
+struct Triple {
+    x: isize,
+    y: isize,
+    z: isize,
+}
+
+fn test(x: bool, foo: Box<Triple>) -> isize {
+    let bar = foo;
+    let mut y: Box<Triple>;
+    if x { y = bar; } else { y = box Triple {x: 4, y: 5, z: 6}; }
+    return y.y;
+}
+
+pub fn main() {
+    let x: Box<_> = box Triple{x: 1, y: 2, z: 3};
+    for _ in 0_usize..10000_usize {
+        assert_eq!(test(true, x.clone()), 2);
+    }
+    assert_eq!(test(false, x), 5);
+}
diff --git a/src/test/ui/moves/move-4-unique.rs b/src/test/ui/moves/move-4-unique.rs
new file mode 100644
index 00000000000..1787caadb7a
--- /dev/null
+++ b/src/test/ui/moves/move-4-unique.rs
@@ -0,0 +1,19 @@
+// run-pass
+#![allow(dead_code)]
+#![feature(box_syntax)]
+
+struct Triple {a: isize, b: isize, c: isize}
+
+fn test(foo: Box<Triple>) -> Box<Triple> {
+    let foo = foo;
+    let bar = foo;
+    let baz = bar;
+    let quux = baz;
+    return quux;
+}
+
+pub fn main() {
+    let x = box Triple{a: 1, b: 2, c: 3};
+    let y = test(x);
+    assert_eq!(y.c, 3);
+}
diff --git a/src/test/ui/moves/move-4.rs b/src/test/ui/moves/move-4.rs
new file mode 100644
index 00000000000..c87c605df77
--- /dev/null
+++ b/src/test/ui/moves/move-4.rs
@@ -0,0 +1,19 @@
+// run-pass
+#![allow(dead_code)]
+#![feature(box_syntax)]
+
+struct Triple { a: isize, b: isize, c: isize }
+
+fn test(foo: Box<Triple>) -> Box<Triple> {
+    let foo = foo;
+    let bar = foo;
+    let baz = bar;
+    let quux = baz;
+    return quux;
+}
+
+pub fn main() {
+    let x = box Triple{a: 1, b: 2, c: 3};
+    let y = test(x);
+    assert_eq!(y.c, 3);
+}
diff --git a/src/test/ui/moves/move-arg-2-unique.rs b/src/test/ui/moves/move-arg-2-unique.rs
new file mode 100644
index 00000000000..fcfd5e14765
--- /dev/null
+++ b/src/test/ui/moves/move-arg-2-unique.rs
@@ -0,0 +1,13 @@
+// run-pass
+#![feature(box_syntax)]
+
+fn test(foo: Box<Vec<isize>> ) { assert_eq!((*foo)[0], 10); }
+
+pub fn main() {
+    let x = box vec![10];
+    // Test forgetting a local by move-in
+    test(x);
+
+    // Test forgetting a temporary by move-in.
+    test(box vec![10]);
+}
diff --git a/src/test/ui/moves/move-arg-2.rs b/src/test/ui/moves/move-arg-2.rs
new file mode 100644
index 00000000000..4cd1f6fe810
--- /dev/null
+++ b/src/test/ui/moves/move-arg-2.rs
@@ -0,0 +1,13 @@
+// run-pass
+#![feature(box_syntax)]
+
+fn test(foo: Box<Vec<isize>>) { assert_eq!((*foo)[0], 10); }
+
+pub fn main() {
+    let x = box vec![10];
+    // Test forgetting a local by move-in
+    test(x);
+
+    // Test forgetting a temporary by move-in.
+    test(box vec![10]);
+}
diff --git a/src/test/ui/moves/move-arg.rs b/src/test/ui/moves/move-arg.rs
new file mode 100644
index 00000000000..5942cd89fd9
--- /dev/null
+++ b/src/test/ui/moves/move-arg.rs
@@ -0,0 +1,5 @@
+// run-pass
+
+fn test(foo: isize) { assert_eq!(foo, 10); }
+
+pub fn main() { let x = 10; test(x); }
diff --git a/src/test/ui/moves/move-nullary-fn.rs b/src/test/ui/moves/move-nullary-fn.rs
new file mode 100644
index 00000000000..14c9262c74d
--- /dev/null
+++ b/src/test/ui/moves/move-nullary-fn.rs
@@ -0,0 +1,13 @@
+// run-pass
+// Issue #922
+// pretty-expanded FIXME #23616
+
+fn f2<F>(_thing: F) where F: FnOnce() { }
+
+fn f<F>(thing: F) where F: FnOnce() {
+    f2(thing);
+}
+
+pub fn main() {
+    f(|| {});
+}
diff --git a/src/test/ui/moves/move-out-of-field.rs b/src/test/ui/moves/move-out-of-field.rs
new file mode 100644
index 00000000000..9f697db4f79
--- /dev/null
+++ b/src/test/ui/moves/move-out-of-field.rs
@@ -0,0 +1,27 @@
+// run-pass
+
+use std::string::String;
+
+struct StringBuffer {
+    s: String,
+}
+
+impl StringBuffer {
+    pub fn append(&mut self, v: &str) {
+        self.s.push_str(v);
+    }
+}
+
+fn to_string(sb: StringBuffer) -> String {
+    sb.s
+}
+
+pub fn main() {
+    let mut sb = StringBuffer {
+        s: String::new(),
+    };
+    sb.append("Hello, ");
+    sb.append("World!");
+    let str = to_string(sb);
+    assert_eq!(str, "Hello, World!");
+}
diff --git a/src/test/ui/moves/move-scalar.rs b/src/test/ui/moves/move-scalar.rs
new file mode 100644
index 00000000000..98bfeb1bc05
--- /dev/null
+++ b/src/test/ui/moves/move-scalar.rs
@@ -0,0 +1,10 @@
+// run-pass
+#![allow(unused_mut)]
+
+pub fn main() {
+
+    let y: isize = 42;
+    let mut x: isize;
+    x = y;
+    assert_eq!(x, 42);
+}
diff --git a/src/test/ui/moves/moves-based-on-type-capture-clause.rs b/src/test/ui/moves/moves-based-on-type-capture-clause.rs
new file mode 100644
index 00000000000..4a6a4ed281d
--- /dev/null
+++ b/src/test/ui/moves/moves-based-on-type-capture-clause.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![allow(unused_must_use)]
+// ignore-emscripten no threads support
+
+use std::thread;
+
+pub fn main() {
+    let x = "Hello world!".to_string();
+    thread::spawn(move|| {
+        println!("{}", x);
+    }).join();
+}