]> git.lizzy.rs Git - rust.git/commitdiff
Add new tests, fix up old tests
authorMichael Goulet <michael@errs.io>
Fri, 7 Jan 2022 18:26:17 +0000 (10:26 -0800)
committerMichael Goulet <michael@errs.io>
Wed, 12 Jan 2022 16:28:41 +0000 (08:28 -0800)
src/test/ui/autoref-autoderef/deref-into-array.rs [new file with mode: 0644]
src/test/ui/const-generics/deref-into-array-generic.rs [new file with mode: 0644]

diff --git a/src/test/ui/autoref-autoderef/deref-into-array.rs b/src/test/ui/autoref-autoderef/deref-into-array.rs
new file mode 100644 (file)
index 0000000..855a82d
--- /dev/null
@@ -0,0 +1,17 @@
+// check-pass
+
+struct Test<T>([T; 1]);
+
+impl<T> std::ops::Deref for Test<T> {
+    type Target = [T; 1];
+
+    fn deref(&self) -> &[T; 1] {
+        &self.0
+    }
+}
+
+fn main() {
+    let out = Test([(); 1]);
+    let blah = out.len();
+    println!("{}", blah);
+}
diff --git a/src/test/ui/const-generics/deref-into-array-generic.rs b/src/test/ui/const-generics/deref-into-array-generic.rs
new file mode 100644 (file)
index 0000000..7d75af1
--- /dev/null
@@ -0,0 +1,27 @@
+// check-pass
+
+struct Test<T, const N: usize>([T; N]);
+
+impl<T: Copy + Default, const N: usize> Default for Test<T, N> {
+    fn default() -> Self {
+        Self([T::default(); N])
+    }
+}
+
+impl<T, const N: usize> std::ops::Deref for Test<T, N> {
+    type Target = [T; N];
+
+    fn deref(&self) -> &[T; N] {
+        &self.0
+    }
+}
+
+fn test() -> Test<u64, 16> {
+    let test = Test::default();
+    println!("{}", test.len());
+    test
+}
+
+fn main() {
+    test();
+}