diff options
| author | David Wood <david@davidtw.co> | 2019-06-09 20:54:28 +0100 |
|---|---|---|
| committer | David Wood <david@davidtw.co> | 2019-06-10 16:58:47 +0100 |
| commit | 9ed4674269f3d1ecedfd173e279087d256d66e77 (patch) | |
| tree | 984954ea572cafd3819077dfc1c08fd1b6e56357 /src/test/ui/const-generics | |
| parent | d132f544f9d74e3cc047ef211e57eae60b78e5c5 (diff) | |
| download | rust-9ed4674269f3d1ecedfd173e279087d256d66e77.tar.gz rust-9ed4674269f3d1ecedfd173e279087d256d66e77.zip | |
typeck: Fix const generic in repeat param ICE.
This commit fixes an ICE that occured when a const generic was used in a repeat expression. This was due to the code expecting the length of the repeat expression to be const evaluatable to a constant, but a const generic parameter is not (however, it can be made into a constant).
Diffstat (limited to 'src/test/ui/const-generics')
| -rw-r--r-- | src/test/ui/const-generics/issue-61336-1.rs | 12 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issue-61336-1.stderr | 14 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issue-61336.rs | 16 | ||||
| -rw-r--r-- | src/test/ui/const-generics/issue-61336.stderr | 18 |
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`. |
