summaryrefslogtreecommitdiffstats
path: root/src/test/ui/zero-sized
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/zero-sized
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/zero-sized')
-rw-r--r--src/test/ui/zero-sized/zero-size-type-destructors.rs21
-rw-r--r--src/test/ui/zero-sized/zero-sized-binary-heap-push.rs20
-rw-r--r--src/test/ui/zero-sized/zero-sized-btreemap-insert.rs25
-rw-r--r--src/test/ui/zero-sized/zero-sized-linkedlist-push.rs29
-rw-r--r--src/test/ui/zero-sized/zero-sized-tuple-struct.rs13
5 files changed, 108 insertions, 0 deletions
diff --git a/src/test/ui/zero-sized/zero-size-type-destructors.rs b/src/test/ui/zero-sized/zero-size-type-destructors.rs
new file mode 100644
index 000000000..fb87d8ea0
--- /dev/null
+++ b/src/test/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/src/test/ui/zero-sized/zero-sized-binary-heap-push.rs b/src/test/ui/zero-sized/zero-sized-binary-heap-push.rs
new file mode 100644
index 000000000..6553c5adb
--- /dev/null
+++ b/src/test/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/src/test/ui/zero-sized/zero-sized-btreemap-insert.rs b/src/test/ui/zero-sized/zero-sized-btreemap-insert.rs
new file mode 100644
index 000000000..52edb33d6
--- /dev/null
+++ b/src/test/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/src/test/ui/zero-sized/zero-sized-linkedlist-push.rs b/src/test/ui/zero-sized/zero-sized-linkedlist-push.rs
new file mode 100644
index 000000000..03724085f
--- /dev/null
+++ b/src/test/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/src/test/ui/zero-sized/zero-sized-tuple-struct.rs b/src/test/ui/zero-sized/zero-sized-tuple-struct.rs
new file mode 100644
index 000000000..2208590f7
--- /dev/null
+++ b/src/test/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);
+}