]> git.lizzy.rs Git - rust.git/commitdiff
add generic param mismatch test
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 10 Nov 2020 08:35:02 +0000 (09:35 +0100)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 10 Nov 2020 08:51:02 +0000 (09:51 +0100)
src/test/ui/const-generics/generic-param-mismatch.full.stderr [new file with mode: 0644]
src/test/ui/const-generics/generic-param-mismatch.min.stderr [new file with mode: 0644]
src/test/ui/const-generics/generic-param-mismatch.rs [new file with mode: 0644]

diff --git a/src/test/ui/const-generics/generic-param-mismatch.full.stderr b/src/test/ui/const-generics/generic-param-mismatch.full.stderr
new file mode 100644 (file)
index 0000000..6befa9d
--- /dev/null
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+  --> $DIR/generic-param-mismatch.rs:7:5
+   |
+LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
+   |                                              ------- expected `[u8; M]` because of return type
+LL |     [0; N]
+   |     ^^^^^^ expected `M`, found `N`
+   |
+   = note: expected array `[u8; M]`
+              found array `[u8; N]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/generic-param-mismatch.min.stderr b/src/test/ui/const-generics/generic-param-mismatch.min.stderr
new file mode 100644 (file)
index 0000000..6befa9d
--- /dev/null
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+  --> $DIR/generic-param-mismatch.rs:7:5
+   |
+LL | fn test<const N: usize, const M: usize>() -> [u8; M] {
+   |                                              ------- expected `[u8; M]` because of return type
+LL |     [0; N]
+   |     ^^^^^^ expected `M`, found `N`
+   |
+   = note: expected array `[u8; M]`
+              found array `[u8; N]`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/const-generics/generic-param-mismatch.rs b/src/test/ui/const-generics/generic-param-mismatch.rs
new file mode 100644 (file)
index 0000000..e409094
--- /dev/null
@@ -0,0 +1,10 @@
+// revisions: full min
+#![cfg_attr(full, allow(incomplete_features))]
+#![cfg_attr(full, feature(const_generics))]
+#![cfg_attr(min, feature(min_const_generics))]
+
+fn test<const N: usize, const M: usize>() -> [u8; M] {
+    [0; N] //~ ERROR mismatched types
+}
+
+fn main() {}