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
This commit is contained in:
Mazdak Farrokhzad 2019-06-11 17:14:04 +02:00 committed by GitHub
commit bd57c187fb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 25 deletions

View file

@ -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]);
}

View file

@ -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

View file

@ -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]);
}

View file

@ -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`.