about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-05-10 20:53:46 +0100
committerPietro Albini <pietro@pietroalbini.org>2019-05-20 11:44:41 +0200
commit1479f930fa695478e1113fb99435ac9cb58085d4 (patch)
tree63180b2a4f74dcd2215207aa57fca39c778f7717
parentce90a9e5ee7206b65cedc5afb5e723a6aeb12f33 (diff)
downloadrust-1479f930fa695478e1113fb99435ac9cb58085d4.tar.gz
rust-1479f930fa695478e1113fb99435ac9cb58085d4.zip
Add a test for failed inference of const types
-rw-r--r--src/test/ui/const-generics/cannot-infer-type-for-const-param.rs11
-rw-r--r--src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr15
2 files changed, 26 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs
new file mode 100644
index 00000000000..c3f5e360fe2
--- /dev/null
+++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.rs
@@ -0,0 +1,11 @@
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+// We should probably be able to infer the types here. However, this test is checking that we don't
+// get an ICE in this case. It may be modified later to not be an error.
+
+struct Foo<const NUM_BYTES: usize>(pub [u8; NUM_BYTES]);
+
+fn main() {
+    let _ = Foo::<3>([1, 2, 3]); //~ ERROR type annotations needed
+}
diff --git a/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr
new file mode 100644
index 00000000000..a0641bd2fdc
--- /dev/null
+++ b/src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr
@@ -0,0 +1,15 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/cannot-infer-type-for-const-param.rs:1:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+
+error[E0282]: type annotations needed
+  --> $DIR/cannot-infer-type-for-const-param.rs:10:19
+   |
+LL |     let _ = Foo::<3>([1, 2, 3]);
+   |                   ^ cannot infer type for `{integer}`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0282`.