Skip to content

Commit

Permalink
Rollup merge of #76514 - hameerabbasi:const-generics-revs, r=lcnr
Browse files Browse the repository at this point in the history
Add revisions to const generic issue UI tests.

Fixes #75279.

I have gotten into the flow, so I can do more of these if requested. I'm looking for feedback as to whether my work is on the right track so far.
  • Loading branch information
tmandry authored Sep 10, 2020
2 parents 91c3ef8 + bec8e5f commit 7565ccc
Show file tree
Hide file tree
Showing 52 changed files with 492 additions and 169 deletions.
4 changes: 3 additions & 1 deletion src/test/ui/const-generics/auxiliary/const_generic_lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(const_generics)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

pub struct Struct<const N: usize>(pub [u8; N]);

Expand Down
4 changes: 3 additions & 1 deletion src/test/ui/const-generics/auxiliary/impl-const.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(const_generics)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

pub struct Num<const N: usize>;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0308]: mismatched types
--> $DIR/const-argument-cross-crate-mismatch.rs:6:67
--> $DIR/const-argument-cross-crate-mismatch.rs:7:67
|
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements

error[E0308]: mismatched types
--> $DIR/const-argument-cross-crate-mismatch.rs:8:65
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
|
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0308]: mismatched types
--> $DIR/const-argument-cross-crate-mismatch.rs:7:67
|
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements

error[E0308]: mismatched types
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
|
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0308`.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// aux-build:const_generic_lib.rs
// revisions: full min

extern crate const_generic_lib;

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/const-generics/const-argument-cross-crate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// run-pass
// revisions: full min
// aux-build:const_generic_lib.rs

extern crate const_generic_lib;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type parameters must be declared prior to const parameters
--> $DIR/complex-unord-param.rs:9:41
|
LL | struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> {
| ---------------------^----------------------^--------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, A: 'a, T: 'a, const N: usize, const M: usize>`

error: aborting due to previous error

10 changes: 6 additions & 4 deletions src/test/ui/const-generics/defaults/complex-unord-param.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// run-pass
// [full] run-pass
// revisions: full min
// Checks a complicated usage of unordered params

#![feature(const_generics)]
#![allow(incomplete_features)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]
#![allow(dead_code)]

struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> {
//[min]~^ ERROR type parameters must be declared prior to const parameters
args: &'a [&'a [T; M]; N],
specifier: A,
}
Expand Down
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/intermixed-lifetime.rs:6:28
--> $DIR/intermixed-lifetime.rs:7:28
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T>`

error: lifetime parameters must be declared prior to type parameters
--> $DIR/intermixed-lifetime.rs:9:37
--> $DIR/intermixed-lifetime.rs:11:37
|
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T>`
Expand Down
26 changes: 26 additions & 0 deletions src/test/ui/const-generics/defaults/intermixed-lifetime.min.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
error: lifetime parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:7:28
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`

error: type parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:7:32
|
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
| ---------------------^------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`

error: lifetime parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:11:37
|
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`

error: type parameters must be declared prior to const parameters
--> $DIR/intermixed-lifetime.rs:11:28
|
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
| -----------------^----------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`

error: aborting due to 4 previous errors

12 changes: 8 additions & 4 deletions src/test/ui/const-generics/defaults/intermixed-lifetime.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// revisions: full min
// Checks that lifetimes cannot be interspersed between consts and types.

#![feature(const_generics)]
#![allow(incomplete_features)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
//~^ Error lifetime parameters must be declared prior to const parameters
//[min]~^^ Error type parameters must be declared prior to const parameters

struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
//~^ Error lifetime parameters must be declared prior to type parameters
//[full]~^ Error lifetime parameters must be declared prior to type parameters
//[min]~^^ Error type parameters must be declared prior to const parameters
//[min]~| Error lifetime parameters must be declared prior to const parameters

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: type parameters must be declared prior to const parameters
--> $DIR/simple-defaults.rs:9:40
|
LL | struct FixedOutput<'a, const N: usize, T=u32> {
| ---------------------^----- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`

error: aborting due to previous error

9 changes: 6 additions & 3 deletions src/test/ui/const-generics/defaults/simple-defaults.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// run-pass
// [full] run-pass
// revisions: min full
// Checks some basic test cases for defaults.
#![feature(const_generics)]
#![allow(incomplete_features)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]
#![allow(dead_code)]

struct FixedOutput<'a, const N: usize, T=u32> {
//[min]~^ ERROR type parameters must be declared prior to const parameters
out: &'a [T; N],
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(const_generics)]
#![cfg_attr(full, feature(const_generics))]
#![cfg_attr(full, allow(incomplete_features))]
#![cfg_attr(min, feature(min_const_generics))]

// All of these three items must be in `lib2` to reproduce the error

Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-61935.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-61935.rs:10:14
|
LL | Self:FooImpl<{N==0}>
| ^^^^^^^^^^^^^^^
|
= 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-61935.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-61935.rs:10:23
|
LL | Self:FooImpl<{N==0}>
| ^ 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-61935.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 Foo {}

impl<const N: usize> Foo for [(); N]
where
Self:FooImpl<{N==0}>
//~^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
{}

trait FooImpl<const IS_ZERO: bool>{}
Expand Down
19 changes: 0 additions & 19 deletions src/test/ui/const-generics/issues/issue-61935.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// 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))]

pub trait BitLen: Sized {
const BIT_LEN: usize;
Expand All @@ -12,5 +14,5 @@ impl<const L: usize> BitLen for [u8; L] {
}

fn main() {
let foo = <[u8; 2]>::BIT_LEN; //~ WARN unused variable
let _foo = <[u8; 2]>::BIT_LEN;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-62220.rs:10:27
--> $DIR/issue-62220.rs:13:27
|
LL | pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-62220.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-62220.rs:8:59
|
LL | pub type TruncatedVector<T, const N: usize> = Vector<T, { 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-62220.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#![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))]

pub struct Vector<T, const N: usize>([T; N]);

pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
//[min]~^ ERROR generic parameters must not be used inside of non trivial constant values

impl<T, const N: usize> Vector<T, { N }> {
/// Drop the last component and return the vector with one fewer dimension.
pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
//~^ ERROR constant expression depends on a generic parameter
//[full]~^ ERROR constant expression depends on a generic parameter
unimplemented!()
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-62456.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-62456.rs:7:20
|
LL | let _ = [0u64; 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-62456.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-62456.rs:7:20
|
LL | let _ = [0u64; 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-62456.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#![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))]

fn foo<const N: usize>() {
let _ = [0u64; 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() {}
19 changes: 0 additions & 19 deletions src/test/ui/const-generics/issues/issue-62456.stderr

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: constant expression depends on a generic parameter
--> $DIR/issue-62504.rs:18:25
--> $DIR/issue-62504.rs:19:25
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^
Expand Down
10 changes: 10 additions & 0 deletions src/test/ui/const-generics/issues/issue-62504.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-62504.rs:19:25
|
LL | ArrayHolder([0; Self::SIZE])
| ^^^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
|
= help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants

error: aborting due to previous error

Loading

0 comments on commit 7565ccc

Please sign in to comment.