about summary refs log tree commit diff
path: root/src/test/ui/const-generics
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-06-11 17:14:04 +0200
committerGitHub <noreply@github.com>2019-06-11 17:14:04 +0200
commitbd57c187fbcc55afc214120e26b2fb81ccecf68a (patch)
tree54688abfa9072ba2e4bcda8edbe38c302be931a3 /src/test/ui/const-generics
parentb3169552e2bf6ba8f9d3a8898acdcbd8f6aa3ac6 (diff)
parent9ed4674269f3d1ecedfd173e279087d256d66e77 (diff)
downloadrust-bd57c187fbcc55afc214120e26b2fb81ccecf68a.tar.gz
rust-bd57c187fbcc55afc214120e26b2fb81ccecf68a.zip
Rollup merge of #61698 - davidtwco:ice-const-generic-length, r=varkor
typeck: Fix const generic in repeat param ICE.

Fixes #61336. Turns out this wasn't related to #49147 after all.

r? @varkor
Diffstat (limited to 'src/test/ui/const-generics')
-rw-r--r--src/test/ui/const-generics/issue-61336-1.rs12
-rw-r--r--src/test/ui/const-generics/issue-61336-1.stderr14
-rw-r--r--src/test/ui/const-generics/issue-61336.rs16
-rw-r--r--src/test/ui/const-generics/issue-61336.stderr18
4 files changed, 60 insertions, 0 deletions
diff --git a/src/test/ui/const-generics/issue-61336-1.rs b/src/test/ui/const-generics/issue-61336-1.rs
new file mode 100644
index 00000000000..5b5e431bf2f
--- /dev/null
+++ b/src/test/ui/const-generics/issue-61336-1.rs
@@ -0,0 +1,12 @@
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
+    [x; N]
+    //~^ ERROR array lengths can't depend on generic parameters
+}
+
+fn main() {
+    let x: [u32; 5] = f::<u32, 5>(3);
+    assert_eq!(x, [3u32; 5]);
+}
diff --git a/src/test/ui/const-generics/issue-61336-1.stderr b/src/test/ui/const-generics/issue-61336-1.stderr
new file mode 100644
index 00000000000..1a5bb9f763b
--- /dev/null
+++ b/src/test/ui/const-generics/issue-61336-1.stderr
@@ -0,0 +1,14 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/issue-61336-1.rs:1:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+
+error: array lengths can't depend on generic parameters
+  --> $DIR/issue-61336-1.rs:5:9
+   |
+LL |     [x; N]
+   |         ^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/const-generics/issue-61336.rs b/src/test/ui/const-generics/issue-61336.rs
new file mode 100644
index 00000000000..95930371d59
--- /dev/null
+++ b/src/test/ui/const-generics/issue-61336.rs
@@ -0,0 +1,16 @@
+#![feature(const_generics)]
+//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
+
+fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
+    [x; N]
+}
+
+fn g<T, const N: usize>(x: T) -> [T; N] {
+    [x; N]
+    //~^ ERROR the trait bound `T: std::marker::Copy` is not satisfied [E0277]
+}
+
+fn main() {
+    let x: [u32; 5] = f::<u32, 5>(3);
+    assert_eq!(x, [3u32; 5]);
+}
diff --git a/src/test/ui/const-generics/issue-61336.stderr b/src/test/ui/const-generics/issue-61336.stderr
new file mode 100644
index 00000000000..9939a599834
--- /dev/null
+++ b/src/test/ui/const-generics/issue-61336.stderr
@@ -0,0 +1,18 @@
+warning: the feature `const_generics` is incomplete and may cause the compiler to crash
+  --> $DIR/issue-61336.rs:1:12
+   |
+LL | #![feature(const_generics)]
+   |            ^^^^^^^^^^^^^^
+
+error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
+  --> $DIR/issue-61336.rs:9:5
+   |
+LL |     [x; N]
+   |     ^^^^^^ the trait `std::marker::Copy` is not implemented for `T`
+   |
+   = help: consider adding a `where T: std::marker::Copy` bound
+   = note: the `Copy` trait is required because the repeated element will be copied
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0277`.