Skip to content

Commit

Permalink
Rollup merge of #75938 - Amjad50:min_const_generics-tests-revisions, …
Browse files Browse the repository at this point in the history
…r=lcnr

Added some `min_const_generics` revisions into `const_generics` tests

Help in #75279. still a lot more to cover though

r? @lcnr
  • Loading branch information
matklad authored Aug 31, 2020
2 parents 3b4797c + 668f63d commit 4e2a25d
Show file tree
Hide file tree
Showing 107 changed files with 762 additions and 375 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: lifetime parameters must be declared prior to const parameters
--> $DIR/argument_order.rs:9:32
--> $DIR/argument_order.rs:12:32
|
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>`

error[E0747]: lifetime provided when a type was expected
--> $DIR/argument_order.rs:16:23
--> $DIR/argument_order.rs:20:23
|
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
| ^^^^^^^
Expand Down
30 changes: 30 additions & 0 deletions src/test/ui/const-generics/argument_order.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
error: type parameters must be declared prior to const parameters
--> $DIR/argument_order.rs:6:28
|
LL | struct Bad<const N: usize, T> {
| -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>`

error: lifetime parameters must be declared prior to const parameters
--> $DIR/argument_order.rs:12:32
|
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`

error: type parameters must be declared prior to const parameters
--> $DIR/argument_order.rs:12:36
|
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
| ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`

error[E0747]: lifetime provided when a type was expected
--> $DIR/argument_order.rs:20:23
|
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
| ^^^^^^^
|
= note: lifetime arguments must be provided before type arguments
= help: reorder the arguments: lifetimes, then types, then consts: `<'a, 'b, T, U, N, M>`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0747`.
8 changes: 6 additions & 2 deletions src/test/ui/const-generics/argument_order.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

struct Bad<const N: usize, T> {
//[min]~^ ERROR type parameters must be declared prior to const parameters
arr: [u8; { N }],
another: T,
}

struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
//~^ ERROR lifetime parameters must be declared prior
//[min]~^^ ERROR type parameters must be declared prior to const parameters
a: &'a T,
b: &'b U,
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/ui/const-generics/array-wrapper-struct-ctor.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// run-pass

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

#![allow(dead_code)]

Expand Down
11 changes: 0 additions & 11 deletions src/test/ui/const-generics/array-wrapper-struct-ctor.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// check-pass
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

// This test confirms that the types can be inferred correctly for this example with const
// generics. Previously this would ICE, and more recently error.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0747]: constant provided when a type was expected
--> $DIR/const-arg-type-arg-misordered.rs:6:35
--> $DIR/const-arg-type-arg-misordered.rs:8:35
|
LL | fn foo<const N: usize>() -> Array<N, ()> {
| ^
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
error[E0747]: constant provided when a type was expected
--> $DIR/const-arg-type-arg-misordered.rs:8:35
|
LL | fn foo<const N: usize>() -> Array<N, ()> {
| ^
|
= note: type arguments must be provided before constant arguments
= help: reorder the arguments: types, then consts: `<T, N>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0747`.
9 changes: 6 additions & 3 deletions src/test/ui/const-generics/const-arg-type-arg-misordered.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

type Array<T, const N: usize> = [T; N];

fn foo<const N: usize>() -> Array<N, ()> { //~ ERROR constant provided when a type was expected
fn foo<const N: usize>() -> Array<N, ()> {
//~^ ERROR constant provided when a type was expected
unimplemented!()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: lifetime parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:4:21
--> $DIR/const-param-before-other-params.rs:6:21
|
LL | fn bar<const X: (), 'a>(_: &'a ()) {
| --------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const X: ()>`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error: lifetime parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:6:21
|
LL | fn bar<const X: (), 'a>(_: &'a ()) {
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`

error: type parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:11:21
|
LL | fn foo<const X: (), T>(_: &T) {}
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`

error: `()` is forbidden as the type of a const generic parameter
--> $DIR/const-param-before-other-params.rs:6:17
|
LL | fn bar<const X: (), 'a>(_: &'a ()) {
| ^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: `()` is forbidden as the type of a const generic parameter
--> $DIR/const-param-before-other-params.rs:11:17
|
LL | fn foo<const X: (), T>(_: &T) {}
| ^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error: aborting due to 4 previous errors

9 changes: 7 additions & 2 deletions src/test/ui/const-generics/const-param-before-other-params.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#![allow(incomplete_features)]
#![feature(const_generics)]
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

fn bar<const X: (), 'a>(_: &'a ()) {
//~^ ERROR lifetime parameters must be declared prior to const parameters
//[min]~^^ ERROR `()` is forbidden as the type of a const generic parameter
}

fn foo<const X: (), T>(_: &T) {}
//[min]~^ ERROR type parameters must be declared prior to const parameters
//[min]~^^ ERROR `()` is forbidden as the type of a const generic parameter

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
--> $DIR/issue-63322-forbid-dyn.rs:10:18
|
LL | fn test<const T: &'static dyn A>() {
| ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0741`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: `&'static (dyn A + 'static)` is forbidden as the type of a const generic parameter
--> $DIR/issue-63322-forbid-dyn.rs:10:18
|
LL | fn test<const T: &'static dyn A>() {
| ^^^^^^^^^^^^^^
|
= note: the only supported types are integers, `bool` and `char`
= note: more complex types are supported with `#[feature(const_generics)]`

error[E0741]: `&'static (dyn A + 'static)` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
--> $DIR/issue-63322-forbid-dyn.rs:10:18
|
LL | fn test<const T: &'static dyn A>() {
| ^^^^^^^^^^^^^^ `&'static (dyn A + 'static)` doesn't derive both `PartialEq` and `Eq`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0741`.
7 changes: 5 additions & 2 deletions src/test/ui/const-generics/issues/issue-63322-forbid-dyn.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

trait A {}
struct B;
impl A for B {}

fn test<const T: &'static dyn A>() {
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]` to be used
//[min]~^^ ERROR `&'static (dyn A + 'static)` is forbidden
unimplemented!()
}

Expand Down
18 changes: 0 additions & 18 deletions src/test/ui/const-generics/issues/issue-63322-forbid-dyn.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-64494.rs:14:53
--> $DIR/issue-64494.rs:16:53
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
| ^^^^
|
= note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
--> $DIR/issue-64494.rs:16:53
--> $DIR/issue-64494.rs:19:53
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
| ^^^^
Expand Down
28 changes: 28 additions & 0 deletions src/test/ui/const-generics/issues/issue-64494.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
error: generic parameters must not be used inside of non trivial constant values
--> $DIR/issue-64494.rs:16:38
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
| ^^^^^^ non-trivial anonymous constants must not depend on the parameter `T`
|
= help: it is currently only allowed to use either `T` or `{ T }` as generic constants

error: generic parameters must not be used inside of non trivial constant values
--> $DIR/issue-64494.rs:19:38
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
| ^^^^^^ non-trivial anonymous constants must not depend on the parameter `T`
|
= help: it is currently only allowed to use either `T` or `{ T }` as generic constants

error[E0119]: conflicting implementations of trait `MyTrait`:
--> $DIR/issue-64494.rs:19:1
|
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
| ------------------------------------ first implementation here
...
LL | impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0119`.
13 changes: 9 additions & 4 deletions src/test/ui/const-generics/issues/issue-64494.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(const_generics)]
#![allow(incomplete_features)]
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

trait Foo {
const VAL: usize;
Expand All @@ -12,8 +14,11 @@ struct Is<const T: bool>;
impl True for Is<{true}> {}

impl<T: Foo> MyTrait for T where Is<{T::VAL == 5}>: True {}
//~^ ERROR constant expression depends on a generic parameter
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
impl<T: Foo> MyTrait for T where Is<{T::VAL == 6}>: True {}
//~^ ERROR constant expression depends on a generic parameter
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
//[min]~| ERROR conflicting implementations of trait `MyTrait`

fn main() {}
7 changes: 4 additions & 3 deletions src/test/ui/const-generics/issues/issue-64519.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// check-pass

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

struct Foo<const D: usize> {
state: Option<[u8; D]>,
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-66205.full.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-66205.rs:8:12
|
LL | fact::<{ N - 1 }>();
| ^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes

error: aborting due to previous error

10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-66205.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: generic parameters must not be used inside of non trivial constant values
--> $DIR/issue-66205.rs:8:14
|
LL | fact::<{ N - 1 }>();
| ^ non-trivial anonymous constants must not depend on the parameter `N`
|
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants

error: aborting due to previous error

9 changes: 6 additions & 3 deletions src/test/ui/const-generics/issues/issue-66205.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// revisions: full min
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]
#![allow(dead_code, unconditional_recursion)]
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete

fn fact<const N: usize>() {
fact::<{ N - 1 }>();
//~^ ERROR constant expression depends on a generic parameter
//[full]~^ ERROR constant expression depends on a generic parameter
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
}

fn main() {}
Loading

0 comments on commit 4e2a25d

Please sign in to comment.