summaryrefslogtreecommitdiffstats
path: root/tests/ui/box/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/box/unit')
-rw-r--r--tests/ui/box/unit/expr-block-generic-unique1.rs18
-rw-r--r--tests/ui/box/unit/expr-block-generic-unique2.rs14
-rw-r--r--tests/ui/box/unit/expr-if-unique.rs9
-rw-r--r--tests/ui/box/unit/unique-assign-copy.rs12
-rw-r--r--tests/ui/box/unit/unique-assign-drop.rs10
-rw-r--r--tests/ui/box/unit/unique-assign-generic.rs11
-rw-r--r--tests/ui/box/unit/unique-assign.rs8
-rw-r--r--tests/ui/box/unit/unique-autoderef-field.rs10
-rw-r--r--tests/ui/box/unit/unique-autoderef-index.rs6
-rw-r--r--tests/ui/box/unit/unique-cmp.rs11
-rw-r--r--tests/ui/box/unit/unique-containing-tag.rs25
-rw-r--r--tests/ui/box/unit/unique-create.rs11
-rw-r--r--tests/ui/box/unit/unique-decl-init-copy.rs11
-rw-r--r--tests/ui/box/unit/unique-decl-init.rs7
-rw-r--r--tests/ui/box/unit/unique-decl-move.rs7
-rw-r--r--tests/ui/box/unit/unique-decl.rs11
-rw-r--r--tests/ui/box/unit/unique-deref.rs6
-rw-r--r--tests/ui/box/unit/unique-destructure.rs9
-rw-r--r--tests/ui/box/unit/unique-drop-complex.rs6
-rw-r--r--tests/ui/box/unit/unique-ffi-symbols.rs16
-rw-r--r--tests/ui/box/unit/unique-fn-arg-move.rs10
-rw-r--r--tests/ui/box/unit/unique-fn-arg-mut.rs11
-rw-r--r--tests/ui/box/unit/unique-fn-arg.rs11
-rw-r--r--tests/ui/box/unit/unique-fn-ret.rs9
-rw-r--r--tests/ui/box/unit/unique-generic-assign.rs11
-rw-r--r--tests/ui/box/unit/unique-in-tag.rs20
-rw-r--r--tests/ui/box/unit/unique-in-vec-copy.rs15
-rw-r--r--tests/ui/box/unit/unique-in-vec.rs6
-rw-r--r--tests/ui/box/unit/unique-init.rs6
-rw-r--r--tests/ui/box/unit/unique-kinds.rs64
-rw-r--r--tests/ui/box/unit/unique-log.rs6
-rw-r--r--tests/ui/box/unit/unique-match-discrim.rs12
-rw-r--r--tests/ui/box/unit/unique-move-drop.rs10
-rw-r--r--tests/ui/box/unit/unique-move-temp.rs8
-rw-r--r--tests/ui/box/unit/unique-move.rs9
-rw-r--r--tests/ui/box/unit/unique-mutable.rs7
-rw-r--r--tests/ui/box/unit/unique-object-move.rs18
-rw-r--r--tests/ui/box/unit/unique-object-noncopyable.rs25
-rw-r--r--tests/ui/box/unit/unique-object-noncopyable.stderr25
-rw-r--r--tests/ui/box/unit/unique-pat-2.rs18
-rw-r--r--tests/ui/box/unit/unique-pat-3.rs16
-rw-r--r--tests/ui/box/unit/unique-pat.rs14
-rw-r--r--tests/ui/box/unit/unique-pinned-nocopy.rs14
-rw-r--r--tests/ui/box/unit/unique-pinned-nocopy.stderr28
-rw-r--r--tests/ui/box/unit/unique-rec.rs9
-rw-r--r--tests/ui/box/unit/unique-send-2.rs33
-rw-r--r--tests/ui/box/unit/unique-send.rs10
-rw-r--r--tests/ui/box/unit/unique-swap.rs11
-rw-r--r--tests/ui/box/unit/unwind-unique.rs15
49 files changed, 669 insertions, 0 deletions
diff --git a/tests/ui/box/unit/expr-block-generic-unique1.rs b/tests/ui/box/unit/expr-block-generic-unique1.rs
new file mode 100644
index 000000000..14603a2c7
--- /dev/null
+++ b/tests/ui/box/unit/expr-block-generic-unique1.rs
@@ -0,0 +1,18 @@
+// run-pass
+#![allow(unused_braces)]
+
+fn test_generic<T, F>(expected: Box<T>, eq: F) where T: Clone, F: FnOnce(Box<T>, Box<T>) -> bool {
+ let actual: Box<T> = { expected.clone() };
+ assert!(eq(expected, actual));
+}
+
+fn test_box() {
+ fn compare_box(b1: Box<bool>, b2: Box<bool>) -> bool {
+ println!("{}", *b1);
+ println!("{}", *b2);
+ return *b1 == *b2;
+ }
+ test_generic::<bool, _>(Box::new(true), compare_box);
+}
+
+pub fn main() { test_box(); }
diff --git a/tests/ui/box/unit/expr-block-generic-unique2.rs b/tests/ui/box/unit/expr-block-generic-unique2.rs
new file mode 100644
index 000000000..7879c144b
--- /dev/null
+++ b/tests/ui/box/unit/expr-block-generic-unique2.rs
@@ -0,0 +1,14 @@
+// run-pass
+#![allow(unused_braces)]
+
+fn test_generic<T, F>(expected: T, eq: F) where T: Clone, F: FnOnce(T, T) -> bool {
+ let actual: T = { expected.clone() };
+ assert!(eq(expected, actual));
+}
+
+fn test_vec() {
+ fn compare_vec(v1: Box<isize>, v2: Box<isize>) -> bool { return v1 == v2; }
+ test_generic::<Box<isize>, _>(Box::new(1), compare_vec);
+}
+
+pub fn main() { test_vec(); }
diff --git a/tests/ui/box/unit/expr-if-unique.rs b/tests/ui/box/unit/expr-if-unique.rs
new file mode 100644
index 000000000..862326835
--- /dev/null
+++ b/tests/ui/box/unit/expr-if-unique.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+// Tests for if as expressions returning boxed types
+fn test_box() {
+ let rs: Box<_> = if true { Box::new(100) } else { Box::new(101) };
+ assert_eq!(*rs, 100);
+}
+
+pub fn main() { test_box(); }
diff --git a/tests/ui/box/unit/unique-assign-copy.rs b/tests/ui/box/unit/unique-assign-copy.rs
new file mode 100644
index 000000000..b742973ce
--- /dev/null
+++ b/tests/ui/box/unit/unique-assign-copy.rs
@@ -0,0 +1,12 @@
+// run-pass
+
+pub fn main() {
+ let mut i: Box<_> = Box::new(1);
+ // Should be a copy
+ let mut j;
+ j = i.clone();
+ *i = 2;
+ *j = 3;
+ assert_eq!(*i, 2);
+ assert_eq!(*j, 3);
+}
diff --git a/tests/ui/box/unit/unique-assign-drop.rs b/tests/ui/box/unit/unique-assign-drop.rs
new file mode 100644
index 000000000..e7685b589
--- /dev/null
+++ b/tests/ui/box/unit/unique-assign-drop.rs
@@ -0,0 +1,10 @@
+// run-pass
+#![allow(unused_assignments)]
+
+pub fn main() {
+ let i: Box<_> = Box::new(1);
+ let mut j: Box<_> = Box::new(2);
+ // Should drop the previous value of j
+ j = i;
+ assert_eq!(*j, 1);
+}
diff --git a/tests/ui/box/unit/unique-assign-generic.rs b/tests/ui/box/unit/unique-assign-generic.rs
new file mode 100644
index 000000000..d4932d833
--- /dev/null
+++ b/tests/ui/box/unit/unique-assign-generic.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+fn f<T>(t: T) -> T {
+ let t1 = t;
+ t1
+}
+
+pub fn main() {
+ let t = f::<Box<_>>(Box::new(100));
+ assert_eq!(t, Box::new(100));
+}
diff --git a/tests/ui/box/unit/unique-assign.rs b/tests/ui/box/unit/unique-assign.rs
new file mode 100644
index 000000000..d598744f1
--- /dev/null
+++ b/tests/ui/box/unit/unique-assign.rs
@@ -0,0 +1,8 @@
+// run-pass
+#![allow(unused_mut)]
+
+pub fn main() {
+ let mut i: Box<_>;
+ i = Box::new(1);
+ assert_eq!(*i, 1);
+}
diff --git a/tests/ui/box/unit/unique-autoderef-field.rs b/tests/ui/box/unit/unique-autoderef-field.rs
new file mode 100644
index 000000000..64147e11f
--- /dev/null
+++ b/tests/ui/box/unit/unique-autoderef-field.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+struct J { j: isize }
+
+pub fn main() {
+ let i: Box<_> = Box::new(J {
+ j: 100
+ });
+ assert_eq!(i.j, 100);
+}
diff --git a/tests/ui/box/unit/unique-autoderef-index.rs b/tests/ui/box/unit/unique-autoderef-index.rs
new file mode 100644
index 000000000..ea6598a7f
--- /dev/null
+++ b/tests/ui/box/unit/unique-autoderef-index.rs
@@ -0,0 +1,6 @@
+// run-pass
+
+pub fn main() {
+ let i: Box<_> = Box::new(vec![100]);
+ assert_eq!((*i)[0], 100);
+}
diff --git a/tests/ui/box/unit/unique-cmp.rs b/tests/ui/box/unit/unique-cmp.rs
new file mode 100644
index 000000000..ee05dd5a3
--- /dev/null
+++ b/tests/ui/box/unit/unique-cmp.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(unused_allocation)]
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ assert_eq!(i, Box::new(100));
+ assert!(i < Box::new(101));
+ assert!(i <= Box::new(100));
+ assert!(i > Box::new(99));
+ assert!(i >= Box::new(99));
+}
diff --git a/tests/ui/box/unit/unique-containing-tag.rs b/tests/ui/box/unit/unique-containing-tag.rs
new file mode 100644
index 000000000..6c31ae99b
--- /dev/null
+++ b/tests/ui/box/unit/unique-containing-tag.rs
@@ -0,0 +1,25 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ enum t { t1(isize), t2(isize), }
+
+ let _x: Box<_> = Box::new(t::t1(10));
+
+ /*alt *x {
+ t1(a) {
+ assert_eq!(a, 10);
+ }
+ _ { panic!(); }
+ }*/
+
+ /*alt x {
+ Box::new(t1(a) {
+ assert_eq!(a, 10);
+ })
+ _ { panic!(); }
+ }*/
+}
diff --git a/tests/ui/box/unit/unique-create.rs b/tests/ui/box/unit/unique-create.rs
new file mode 100644
index 000000000..c566e7962
--- /dev/null
+++ b/tests/ui/box/unit/unique-create.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(dead_code)]
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ let _: Box<_> = Box::new(100);
+}
+
+fn vec() {
+ vec![0];
+}
diff --git a/tests/ui/box/unit/unique-decl-init-copy.rs b/tests/ui/box/unit/unique-decl-init-copy.rs
new file mode 100644
index 000000000..5b9576fcc
--- /dev/null
+++ b/tests/ui/box/unit/unique-decl-init-copy.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+pub fn main() {
+ let mut i: Box<_> = Box::new(1);
+ // Should be a copy
+ let mut j = i.clone();
+ *i = 2;
+ *j = 3;
+ assert_eq!(*i, 2);
+ assert_eq!(*j, 3);
+}
diff --git a/tests/ui/box/unit/unique-decl-init.rs b/tests/ui/box/unit/unique-decl-init.rs
new file mode 100644
index 000000000..1d70860c7
--- /dev/null
+++ b/tests/ui/box/unit/unique-decl-init.rs
@@ -0,0 +1,7 @@
+// run-pass
+
+pub fn main() {
+ let i: Box<_> = Box::new(1);
+ let j = i;
+ assert_eq!(*j, 1);
+}
diff --git a/tests/ui/box/unit/unique-decl-move.rs b/tests/ui/box/unit/unique-decl-move.rs
new file mode 100644
index 000000000..21187510f
--- /dev/null
+++ b/tests/ui/box/unit/unique-decl-move.rs
@@ -0,0 +1,7 @@
+// run-pass
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ let j = i;
+ assert_eq!(*j, 100);
+}
diff --git a/tests/ui/box/unit/unique-decl.rs b/tests/ui/box/unit/unique-decl.rs
new file mode 100644
index 000000000..84a1b2a5b
--- /dev/null
+++ b/tests/ui/box/unit/unique-decl.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(dead_code)]
+
+
+pub fn main() {
+ let _: Box<isize>;
+}
+
+fn f(_i: Box<isize>) -> Box<isize> {
+ panic!();
+}
diff --git a/tests/ui/box/unit/unique-deref.rs b/tests/ui/box/unit/unique-deref.rs
new file mode 100644
index 000000000..33a1e9932
--- /dev/null
+++ b/tests/ui/box/unit/unique-deref.rs
@@ -0,0 +1,6 @@
+// run-pass
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ assert_eq!(*i, 100);
+}
diff --git a/tests/ui/box/unit/unique-destructure.rs b/tests/ui/box/unit/unique-destructure.rs
new file mode 100644
index 000000000..7207ac962
--- /dev/null
+++ b/tests/ui/box/unit/unique-destructure.rs
@@ -0,0 +1,9 @@
+// run-pass
+#![feature(box_patterns)]
+
+struct Foo { a: isize, b: isize }
+
+pub fn main() {
+ let box Foo{ a, b } = Box::new(Foo { a: 100, b: 200 });
+ assert_eq!(a + b, 300);
+}
diff --git a/tests/ui/box/unit/unique-drop-complex.rs b/tests/ui/box/unit/unique-drop-complex.rs
new file mode 100644
index 000000000..2324f1e1a
--- /dev/null
+++ b/tests/ui/box/unit/unique-drop-complex.rs
@@ -0,0 +1,6 @@
+// run-pass
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ let _x: Box<_> = Box::new(vec![0,0,0,0,0]);
+}
diff --git a/tests/ui/box/unit/unique-ffi-symbols.rs b/tests/ui/box/unit/unique-ffi-symbols.rs
new file mode 100644
index 000000000..77b5ead26
--- /dev/null
+++ b/tests/ui/box/unit/unique-ffi-symbols.rs
@@ -0,0 +1,16 @@
+// run-pass
+// We used to have a __rust_abi shim that resulted in duplicated symbols
+// whenever the item path wasn't enough to disambiguate between them.
+fn main() {
+ let a = {
+ extern "C" fn good() -> i32 { return 0; }
+ good as extern "C" fn() -> i32
+ };
+ let b = {
+ extern "C" fn good() -> i32 { return 5; }
+ good as extern "C" fn() -> i32
+ };
+
+ assert!(a != b);
+ assert_eq!((a(), b()), (0, 5));
+}
diff --git a/tests/ui/box/unit/unique-fn-arg-move.rs b/tests/ui/box/unit/unique-fn-arg-move.rs
new file mode 100644
index 000000000..6d42df218
--- /dev/null
+++ b/tests/ui/box/unit/unique-fn-arg-move.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+fn f(i: Box<isize>) {
+ assert_eq!(*i, 100);
+}
+
+pub fn main() {
+ let i = Box::new(100);
+ f(i);
+}
diff --git a/tests/ui/box/unit/unique-fn-arg-mut.rs b/tests/ui/box/unit/unique-fn-arg-mut.rs
new file mode 100644
index 000000000..01510200b
--- /dev/null
+++ b/tests/ui/box/unit/unique-fn-arg-mut.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+fn f(i: &mut Box<isize>) {
+ *i = Box::new(200);
+}
+
+pub fn main() {
+ let mut i = Box::new(100);
+ f(&mut i);
+ assert_eq!(*i, 200);
+}
diff --git a/tests/ui/box/unit/unique-fn-arg.rs b/tests/ui/box/unit/unique-fn-arg.rs
new file mode 100644
index 000000000..b4f3bc4b2
--- /dev/null
+++ b/tests/ui/box/unit/unique-fn-arg.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+fn f(i: Box<isize>) {
+ assert_eq!(*i, 100);
+}
+
+pub fn main() {
+ f(Box::new(100));
+ let i = Box::new(100);
+ f(i);
+}
diff --git a/tests/ui/box/unit/unique-fn-ret.rs b/tests/ui/box/unit/unique-fn-ret.rs
new file mode 100644
index 000000000..773a9bce1
--- /dev/null
+++ b/tests/ui/box/unit/unique-fn-ret.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+fn f() -> Box<isize> {
+ Box::new(100)
+}
+
+pub fn main() {
+ assert_eq!(f(), Box::new(100));
+}
diff --git a/tests/ui/box/unit/unique-generic-assign.rs b/tests/ui/box/unit/unique-generic-assign.rs
new file mode 100644
index 000000000..9c4405aa8
--- /dev/null
+++ b/tests/ui/box/unit/unique-generic-assign.rs
@@ -0,0 +1,11 @@
+// run-pass
+#![allow(dead_code)]
+// Issue #976
+
+
+// pretty-expanded FIXME #23616
+
+fn f<T>(x: Box<T>) {
+ let _x2 = x;
+}
+pub fn main() { }
diff --git a/tests/ui/box/unit/unique-in-tag.rs b/tests/ui/box/unit/unique-in-tag.rs
new file mode 100644
index 000000000..6daa06fb1
--- /dev/null
+++ b/tests/ui/box/unit/unique-in-tag.rs
@@ -0,0 +1,20 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+
+fn test1() {
+ enum bar { u(Box<isize>), w(isize), }
+
+ let x = bar::u(Box::new(10));
+ assert!(match x {
+ bar::u(a) => {
+ println!("{}", a);
+ *a
+ }
+ _ => { 66 }
+ } == 10);
+}
+
+pub fn main() {
+ test1();
+}
diff --git a/tests/ui/box/unit/unique-in-vec-copy.rs b/tests/ui/box/unit/unique-in-vec-copy.rs
new file mode 100644
index 000000000..ce52d15ef
--- /dev/null
+++ b/tests/ui/box/unit/unique-in-vec-copy.rs
@@ -0,0 +1,15 @@
+// run-pass
+
+pub fn main() {
+ let mut a: Vec<Box<_>> = vec![Box::new(10)];
+ let b = a.clone();
+
+ assert_eq!(*a[0], 10);
+ assert_eq!(*b[0], 10);
+
+ // This should only modify the value in a, not b
+ *a[0] = 20;
+
+ assert_eq!(*a[0], 20);
+ assert_eq!(*b[0], 10);
+}
diff --git a/tests/ui/box/unit/unique-in-vec.rs b/tests/ui/box/unit/unique-in-vec.rs
new file mode 100644
index 000000000..1e8d05e3d
--- /dev/null
+++ b/tests/ui/box/unit/unique-in-vec.rs
@@ -0,0 +1,6 @@
+// run-pass
+
+pub fn main() {
+ let vect : Vec<Box<_>> = vec![Box::new(100)];
+ assert_eq!(vect[0], Box::new(100));
+}
diff --git a/tests/ui/box/unit/unique-init.rs b/tests/ui/box/unit/unique-init.rs
new file mode 100644
index 000000000..d19605046
--- /dev/null
+++ b/tests/ui/box/unit/unique-init.rs
@@ -0,0 +1,6 @@
+// run-pass
+// pretty-expanded FIXME #23616
+
+pub fn main() {
+ let _i: Box<_> = Box::new(100);
+}
diff --git a/tests/ui/box/unit/unique-kinds.rs b/tests/ui/box/unit/unique-kinds.rs
new file mode 100644
index 000000000..f02d0b507
--- /dev/null
+++ b/tests/ui/box/unit/unique-kinds.rs
@@ -0,0 +1,64 @@
+// run-pass
+
+use std::cmp::PartialEq;
+use std::fmt::Debug;
+
+fn sendable() {
+
+ fn f<T:Send + PartialEq + Debug>(i: T, j: T) {
+ assert_eq!(i, j);
+ }
+
+ fn g<T:Send + PartialEq>(i: T, j: T) {
+ assert!(i != j);
+ }
+
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(100);
+ f(i, j);
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(101);
+ g(i, j);
+}
+
+fn copyable() {
+
+ fn f<T:PartialEq + Debug>(i: T, j: T) {
+ assert_eq!(i, j);
+ }
+
+ fn g<T:PartialEq>(i: T, j: T) {
+ assert!(i != j);
+ }
+
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(100);
+ f(i, j);
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(101);
+ g(i, j);
+}
+
+fn noncopyable() {
+
+ fn f<T:PartialEq + Debug>(i: T, j: T) {
+ assert_eq!(i, j);
+ }
+
+ fn g<T:PartialEq>(i: T, j: T) {
+ assert!(i != j);
+ }
+
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(100);
+ f(i, j);
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(101);
+ g(i, j);
+}
+
+pub fn main() {
+ sendable();
+ copyable();
+ noncopyable();
+}
diff --git a/tests/ui/box/unit/unique-log.rs b/tests/ui/box/unit/unique-log.rs
new file mode 100644
index 000000000..0715d1662
--- /dev/null
+++ b/tests/ui/box/unit/unique-log.rs
@@ -0,0 +1,6 @@
+// run-pass
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ println!("{}", i);
+}
diff --git a/tests/ui/box/unit/unique-match-discrim.rs b/tests/ui/box/unit/unique-match-discrim.rs
new file mode 100644
index 000000000..6e6d74322
--- /dev/null
+++ b/tests/ui/box/unit/unique-match-discrim.rs
@@ -0,0 +1,12 @@
+// run-pass
+#![allow(dead_code)]
+// Issue #961
+
+// pretty-expanded FIXME #23616
+
+fn altsimple() {
+ match Box::new(true) {
+ _ => { }
+ }
+}
+pub fn main() { }
diff --git a/tests/ui/box/unit/unique-move-drop.rs b/tests/ui/box/unit/unique-move-drop.rs
new file mode 100644
index 000000000..c0f5d8f90
--- /dev/null
+++ b/tests/ui/box/unit/unique-move-drop.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+#![allow(unused_variables)]
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ let j: Box<_> = Box::new(200);
+ let j = i;
+ assert_eq!(*j, 100);
+}
diff --git a/tests/ui/box/unit/unique-move-temp.rs b/tests/ui/box/unit/unique-move-temp.rs
new file mode 100644
index 000000000..103af8e1f
--- /dev/null
+++ b/tests/ui/box/unit/unique-move-temp.rs
@@ -0,0 +1,8 @@
+// run-pass
+#![allow(unused_mut)]
+
+pub fn main() {
+ let mut i: Box<_>;
+ i = Box::new(100);
+ assert_eq!(*i, 100);
+}
diff --git a/tests/ui/box/unit/unique-move.rs b/tests/ui/box/unit/unique-move.rs
new file mode 100644
index 000000000..40a2718e4
--- /dev/null
+++ b/tests/ui/box/unit/unique-move.rs
@@ -0,0 +1,9 @@
+// run-pass
+#![allow(unused_mut)]
+
+pub fn main() {
+ let i: Box<_> = Box::new(100);
+ let mut j;
+ j = i;
+ assert_eq!(*j, 100);
+}
diff --git a/tests/ui/box/unit/unique-mutable.rs b/tests/ui/box/unit/unique-mutable.rs
new file mode 100644
index 000000000..0367c0809
--- /dev/null
+++ b/tests/ui/box/unit/unique-mutable.rs
@@ -0,0 +1,7 @@
+// run-pass
+
+pub fn main() {
+ let mut i: Box<_> = Box::new(0);
+ *i = 1;
+ assert_eq!(*i, 1);
+}
diff --git a/tests/ui/box/unit/unique-object-move.rs b/tests/ui/box/unit/unique-object-move.rs
new file mode 100644
index 000000000..bb35a9b2d
--- /dev/null
+++ b/tests/ui/box/unit/unique-object-move.rs
@@ -0,0 +1,18 @@
+// run-pass
+#![allow(dead_code)]
+// Issue #5192
+
+// pretty-expanded FIXME #23616
+
+pub trait EventLoop { fn foo(&self) {} }
+
+pub struct UvEventLoop {
+ uvio: isize
+}
+
+impl EventLoop for UvEventLoop { }
+
+pub fn main() {
+ let loop_: Box<dyn EventLoop> = Box::new(UvEventLoop { uvio: 0 }) as Box<dyn EventLoop>;
+ let _loop2_ = loop_;
+}
diff --git a/tests/ui/box/unit/unique-object-noncopyable.rs b/tests/ui/box/unit/unique-object-noncopyable.rs
new file mode 100644
index 000000000..2c40dfc7a
--- /dev/null
+++ b/tests/ui/box/unit/unique-object-noncopyable.rs
@@ -0,0 +1,25 @@
+trait Foo {
+ fn f(&self);
+}
+
+struct Bar {
+ x: isize,
+}
+
+impl Drop for Bar {
+ fn drop(&mut self) {}
+}
+
+impl Foo for Bar {
+ fn f(&self) {
+ println!("hi");
+ }
+}
+
+
+
+fn main() {
+ let x = Box::new(Bar { x: 10 });
+ let y: Box<dyn Foo> = x as Box<dyn Foo>;
+ let _z = y.clone(); //~ ERROR the method
+}
diff --git a/tests/ui/box/unit/unique-object-noncopyable.stderr b/tests/ui/box/unit/unique-object-noncopyable.stderr
new file mode 100644
index 000000000..db42ed9ba
--- /dev/null
+++ b/tests/ui/box/unit/unique-object-noncopyable.stderr
@@ -0,0 +1,25 @@
+error[E0599]: the method `clone` exists for struct `Box<dyn Foo>`, but its trait bounds were not satisfied
+ --> $DIR/unique-object-noncopyable.rs:24:16
+ |
+LL | trait Foo {
+ | ---------
+ | |
+ | doesn't satisfy `dyn Foo: Clone`
+ | doesn't satisfy `dyn Foo: Sized`
+...
+LL | let _z = y.clone();
+ | ^^^^^ method cannot be called on `Box<dyn Foo>` due to unsatisfied trait bounds
+ --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
+ ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
+ |
+ = note: doesn't satisfy `Box<dyn Foo>: Clone`
+ |
+ = note: the following trait bounds were not satisfied:
+ `dyn Foo: Sized`
+ which is required by `Box<dyn Foo>: Clone`
+ `dyn Foo: Clone`
+ which is required by `Box<dyn Foo>: Clone`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/box/unit/unique-pat-2.rs b/tests/ui/box/unit/unique-pat-2.rs
new file mode 100644
index 000000000..9c73fd220
--- /dev/null
+++ b/tests/ui/box/unit/unique-pat-2.rs
@@ -0,0 +1,18 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+#![allow(non_shorthand_field_patterns)]
+
+#![feature(box_patterns)]
+
+struct Foo {a: isize, b: usize}
+
+enum bar { u(Box<Foo>), w(isize), }
+
+pub fn main() {
+ let v = match bar::u(Box::new(Foo{ a: 10, b: 40 })) {
+ bar::u(box Foo{ a: a, b: b }) => { a + (b as isize) }
+ _ => { 66 }
+ };
+ assert_eq!(v, 50);
+}
diff --git a/tests/ui/box/unit/unique-pat-3.rs b/tests/ui/box/unit/unique-pat-3.rs
new file mode 100644
index 000000000..2e81f898d
--- /dev/null
+++ b/tests/ui/box/unit/unique-pat-3.rs
@@ -0,0 +1,16 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(non_camel_case_types)]
+
+enum bar { u(Box<isize>), w(isize), }
+
+pub fn main() {
+ let v = match bar::u(10.into()) {
+ bar::u(a) => {
+ println!("{}", a);
+ *a
+ }
+ _ => { 66 }
+ };
+ assert_eq!(v, 10);
+}
diff --git a/tests/ui/box/unit/unique-pat.rs b/tests/ui/box/unit/unique-pat.rs
new file mode 100644
index 000000000..c2474d0e7
--- /dev/null
+++ b/tests/ui/box/unit/unique-pat.rs
@@ -0,0 +1,14 @@
+// run-pass
+
+#![feature(box_patterns)]
+
+fn simple() {
+ match Box::new(true) {
+ box true => { }
+ _ => { panic!(); }
+ }
+}
+
+pub fn main() {
+ simple();
+}
diff --git a/tests/ui/box/unit/unique-pinned-nocopy.rs b/tests/ui/box/unit/unique-pinned-nocopy.rs
new file mode 100644
index 000000000..8edaeef51
--- /dev/null
+++ b/tests/ui/box/unit/unique-pinned-nocopy.rs
@@ -0,0 +1,14 @@
+#[derive(Debug)]
+struct R {
+ b: bool,
+}
+
+impl Drop for R {
+ fn drop(&mut self) {}
+}
+
+fn main() {
+ let i = Box::new(R { b: true });
+ let _j = i.clone(); //~ ERROR the method
+ println!("{:?}", i);
+}
diff --git a/tests/ui/box/unit/unique-pinned-nocopy.stderr b/tests/ui/box/unit/unique-pinned-nocopy.stderr
new file mode 100644
index 000000000..2fd5b0d82
--- /dev/null
+++ b/tests/ui/box/unit/unique-pinned-nocopy.stderr
@@ -0,0 +1,28 @@
+error[E0599]: the method `clone` exists for struct `Box<R>`, but its trait bounds were not satisfied
+ --> $DIR/unique-pinned-nocopy.rs:12:16
+ |
+LL | struct R {
+ | -------- doesn't satisfy `R: Clone`
+...
+LL | let _j = i.clone();
+ | ^^^^^ method cannot be called on `Box<R>` due to unsatisfied trait bounds
+ --> $SRC_DIR/alloc/src/boxed.rs:LL:COL
+ ::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
+ |
+ = note: doesn't satisfy `Box<R>: Clone`
+ |
+ = note: the following trait bounds were not satisfied:
+ `R: Clone`
+ which is required by `Box<R>: Clone`
+ = help: items from traits can only be used if the trait is implemented and in scope
+ = note: the following trait defines an item `clone`, perhaps you need to implement it:
+ candidate #1: `Clone`
+help: consider annotating `R` with `#[derive(Clone)]`
+ |
+LL + #[derive(Clone)]
+LL | struct R {
+ |
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/tests/ui/box/unit/unique-rec.rs b/tests/ui/box/unit/unique-rec.rs
new file mode 100644
index 000000000..9f8ad9bb0
--- /dev/null
+++ b/tests/ui/box/unit/unique-rec.rs
@@ -0,0 +1,9 @@
+// run-pass
+
+struct X { x: isize }
+
+pub fn main() {
+ let x: Box<_> = Box::new(X {x: 1});
+ let bar = x;
+ assert_eq!(bar.x, 1);
+}
diff --git a/tests/ui/box/unit/unique-send-2.rs b/tests/ui/box/unit/unique-send-2.rs
new file mode 100644
index 000000000..23ddd2cdc
--- /dev/null
+++ b/tests/ui/box/unit/unique-send-2.rs
@@ -0,0 +1,33 @@
+// run-pass
+#![allow(unused_must_use)]
+// ignore-emscripten no threads support
+
+use std::sync::mpsc::{channel, Sender};
+use std::thread;
+
+fn child(tx: &Sender<Box<usize>>, i: usize) {
+ tx.send(Box::new(i)).unwrap();
+}
+
+pub fn main() {
+ let (tx, rx) = channel();
+ let n = 100;
+ let mut expected = 0;
+ let ts = (0..n).map(|i| {
+ expected += i;
+ let tx = tx.clone();
+ thread::spawn(move|| {
+ child(&tx, i)
+ })
+ }).collect::<Vec<_>>();
+
+ let mut actual = 0;
+ for _ in 0..n {
+ let j = rx.recv().unwrap();
+ actual += *j;
+ }
+
+ assert_eq!(expected, actual);
+
+ for t in ts { t.join(); }
+}
diff --git a/tests/ui/box/unit/unique-send.rs b/tests/ui/box/unit/unique-send.rs
new file mode 100644
index 000000000..431cc2be5
--- /dev/null
+++ b/tests/ui/box/unit/unique-send.rs
@@ -0,0 +1,10 @@
+// run-pass
+
+use std::sync::mpsc::channel;
+
+pub fn main() {
+ let (tx, rx) = channel::<Box<_>>();
+ tx.send(Box::new(100)).unwrap();
+ let v = rx.recv().unwrap();
+ assert_eq!(v, Box::new(100));
+}
diff --git a/tests/ui/box/unit/unique-swap.rs b/tests/ui/box/unit/unique-swap.rs
new file mode 100644
index 000000000..4f33ff9a8
--- /dev/null
+++ b/tests/ui/box/unit/unique-swap.rs
@@ -0,0 +1,11 @@
+// run-pass
+
+use std::mem::swap;
+
+pub fn main() {
+ let mut i: Box<_> = Box::new(100);
+ let mut j: Box<_> = Box::new(200);
+ swap(&mut i, &mut j);
+ assert_eq!(i, Box::new(200));
+ assert_eq!(j, Box::new(100));
+}
diff --git a/tests/ui/box/unit/unwind-unique.rs b/tests/ui/box/unit/unwind-unique.rs
new file mode 100644
index 000000000..50ecf751a
--- /dev/null
+++ b/tests/ui/box/unit/unwind-unique.rs
@@ -0,0 +1,15 @@
+// run-pass
+// needs-unwind
+// ignore-emscripten no threads support
+
+use std::thread;
+
+fn f() {
+ let _a: Box<_> = Box::new(0);
+ panic!();
+}
+
+pub fn main() {
+ let t = thread::spawn(f);
+ drop(t.join());
+}