summaryrefslogtreecommitdiffstats
path: root/tests/ui/zero-sized
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/zero-sized')
-rw-r--r--tests/ui/zero-sized/zero-size-type-destructors.rs21
-rw-r--r--tests/ui/zero-sized/zero-sized-binary-heap-push.rs20
-rw-r--r--tests/ui/zero-sized/zero-sized-btreemap-insert.rs25
-rw-r--r--tests/ui/zero-sized/zero-sized-linkedlist-push.rs29
-rw-r--r--tests/ui/zero-sized/zero-sized-tuple-struct.rs13
5 files changed, 108 insertions, 0 deletions
diff --git a/tests/ui/zero-sized/zero-size-type-destructors.rs b/tests/ui/zero-sized/zero-size-type-destructors.rs
new file mode 100644
index 000000000..fb87d8ea0
--- /dev/null
+++ b/tests/ui/zero-sized/zero-size-type-destructors.rs
@@ -0,0 +1,21 @@
+// run-pass
+#![allow(non_upper_case_globals)]
+
+static mut destructions : isize = 3;
+
+pub fn foo() {
+ struct Foo;
+
+ impl Drop for Foo {
+ fn drop(&mut self) {
+ unsafe { destructions -= 1 };
+ }
+ }
+
+ let _x = [Foo, Foo, Foo];
+}
+
+pub fn main() {
+ foo();
+ assert_eq!(unsafe { destructions }, 0);
+}
diff --git a/tests/ui/zero-sized/zero-sized-binary-heap-push.rs b/tests/ui/zero-sized/zero-sized-binary-heap-push.rs
new file mode 100644
index 000000000..6553c5adb
--- /dev/null
+++ b/tests/ui/zero-sized/zero-sized-binary-heap-push.rs
@@ -0,0 +1,20 @@
+// run-pass
+#![allow(unused_variables)]
+use std::collections::BinaryHeap;
+use std::iter::Iterator;
+
+fn main() {
+ const N: usize = 8;
+
+ for len in 0..N {
+ let mut tester = BinaryHeap::with_capacity(len);
+ assert_eq!(tester.len(), 0);
+ assert!(tester.capacity() >= len);
+ for bit in 0..len {
+ tester.push(());
+ }
+ assert_eq!(tester.len(), len);
+ assert_eq!(tester.iter().count(), len);
+ tester.clear();
+ }
+}
diff --git a/tests/ui/zero-sized/zero-sized-btreemap-insert.rs b/tests/ui/zero-sized/zero-sized-btreemap-insert.rs
new file mode 100644
index 000000000..52edb33d6
--- /dev/null
+++ b/tests/ui/zero-sized/zero-sized-btreemap-insert.rs
@@ -0,0 +1,25 @@
+// run-pass
+#![allow(unused_variables)]
+#![allow(unused_imports)]
+use std::cmp::{Ord, Ordering, PartialOrd};
+use std::collections::BTreeMap;
+use std::iter::Iterator;
+
+#[derive(Eq, Hash, Debug, Ord, PartialEq, PartialOrd)]
+struct Zst;
+
+fn main() {
+ const N: usize = 8;
+
+ for len in 0..N {
+ let mut tester = BTreeMap::new();
+ assert_eq!(tester.len(), 0);
+ for bit in 0..len {
+ tester.insert(Zst, ());
+ }
+ assert_eq!(tester.len(), if len == 0 { 0 } else { 1 });
+ assert_eq!(tester.iter().count(), if len == 0 { 0 } else { 1 });
+ assert_eq!(tester.get(&Zst).is_some(), len > 0);
+ tester.clear();
+ }
+}
diff --git a/tests/ui/zero-sized/zero-sized-linkedlist-push.rs b/tests/ui/zero-sized/zero-sized-linkedlist-push.rs
new file mode 100644
index 000000000..03724085f
--- /dev/null
+++ b/tests/ui/zero-sized/zero-sized-linkedlist-push.rs
@@ -0,0 +1,29 @@
+// run-pass
+use std::collections::LinkedList;
+use std::iter::Iterator;
+
+fn main() {
+ const N: usize = 8;
+
+ // Test that for all possible sequences of push_front / push_back,
+ // we end up with a LinkedList of the correct size
+
+ for len in 0..N {
+ let mut tester = LinkedList::new();
+ assert_eq!(tester.len(), 0);
+ assert_eq!(tester.front(), None);
+ for case in 0..(1 << len) {
+ assert_eq!(tester.len(), 0);
+ for bit in 0..len {
+ if case & (1 << bit) != 0 {
+ tester.push_front(());
+ } else {
+ tester.push_back(());
+ }
+ }
+ assert_eq!(tester.len(), len);
+ assert_eq!(tester.iter().count(), len);
+ tester.clear();
+ }
+ }
+}
diff --git a/tests/ui/zero-sized/zero-sized-tuple-struct.rs b/tests/ui/zero-sized/zero-sized-tuple-struct.rs
new file mode 100644
index 000000000..2208590f7
--- /dev/null
+++ b/tests/ui/zero-sized/zero-sized-tuple-struct.rs
@@ -0,0 +1,13 @@
+// run-pass
+#![allow(unused_braces)]
+#![allow(unused_assignments)]
+
+// Make sure that the constructor args are codegened for zero-sized tuple structs
+
+struct Foo(());
+
+fn main() {
+ let mut a = 1;
+ Foo({ a = 2 });
+ assert_eq!(a, 2);
+}