Rollup merge of #70939 - varkor:const-generics-regression-tests, r=Centril

Add two const generics regression tests

Closes https://github.com/rust-lang/rust/issues/66596.
Closes https://github.com/rust-lang/rust/issues/61522.
This commit is contained in:
Mazdak Farrokhzad 2020-04-09 18:17:20 +02:00 committed by GitHub
commit 7944f39b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,14 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
//~^ ERROR constant expression depends on a generic parameter
impl<const COUNT: usize> MyArray<COUNT> {
fn inner(&self) -> &[u8; COUNT + 1] {
//~^ ERROR constant expression depends on a generic parameter
&self.0
}
}
fn main() {}

View File

@ -0,0 +1,26 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-61522-array-len-succ.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
error: constant expression depends on a generic parameter
--> $DIR/issue-61522-array-len-succ.rs:4:40
|
LL | pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
| ^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: constant expression depends on a generic parameter
--> $DIR/issue-61522-array-len-succ.rs:8:24
|
LL | fn inner(&self) -> &[u8; COUNT + 1] {
| ^^^^^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes
error: aborting due to 2 previous errors

View File

@ -0,0 +1,16 @@
// check-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
trait Trait<const NAME: &'static str> {
type Assoc;
}
impl Trait<"0"> for () {
type Assoc = ();
}
fn main() {
let _: <() as Trait<"0">>::Assoc = ();
}

View File

@ -0,0 +1,8 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-66596-impl-trait-for-str-const-arg.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default