Skip to content

Commit 7565ccc

Browse files
authored
Rollup merge of #76514 - hameerabbasi:const-generics-revs, r=lcnr
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.
2 parents 91c3ef8 + bec8e5f commit 7565ccc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+492
-169
lines changed

src/test/ui/const-generics/auxiliary/const_generic_lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#![feature(const_generics)]
1+
#![cfg_attr(full, feature(const_generics))]
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(min, feature(min_const_generics))]
24

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

src/test/ui/const-generics/auxiliary/impl-const.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#![feature(const_generics)]
1+
#![cfg_attr(full, feature(const_generics))]
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(min, feature(min_const_generics))]
24

35
pub struct Num<const N: usize>;
46

src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr src/test/ui/const-generics/const-argument-cross-crate-mismatch.full.stderr

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

77
error[E0308]: mismatched types
8-
--> $DIR/const-argument-cross-crate-mismatch.rs:8:65
8+
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
99
|
1010
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
1111
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/const-argument-cross-crate-mismatch.rs:7:67
3+
|
4+
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
5+
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/const-argument-cross-crate-mismatch.rs:9:65
9+
|
10+
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
11+
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/const-generics/const-argument-cross-crate-mismatch.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// aux-build:const_generic_lib.rs
2+
// revisions: full min
23

34
extern crate const_generic_lib;
45

src/test/ui/const-generics/const-argument-cross-crate.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// run-pass
2+
// revisions: full min
23
// aux-build:const_generic_lib.rs
34

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

src/test/ui/const-generics/defaults/complex-unord-param.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// run-pass
1+
// [full] run-pass
2+
// revisions: full min
23
// Checks a complicated usage of unordered params
3-
4-
#![feature(const_generics)]
5-
#![allow(incomplete_features)]
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
67
#![allow(dead_code)]
78

89
struct NestedArrays<'a, const N: usize, A: 'a, const M: usize, T:'a =u32> {
10+
//[min]~^ ERROR type parameters must be declared prior to const parameters
911
args: &'a [&'a [T; M]; N],
1012
specifier: A,
1113
}

src/test/ui/const-generics/defaults/intermixed-lifetime.stderr src/test/ui/const-generics/defaults/intermixed-lifetime.full.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: lifetime parameters must be declared prior to const parameters
2-
--> $DIR/intermixed-lifetime.rs:6:28
2+
--> $DIR/intermixed-lifetime.rs:7:28
33
|
44
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
55
| -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T>`
66

77
error: lifetime parameters must be declared prior to type parameters
8-
--> $DIR/intermixed-lifetime.rs:9:37
8+
--> $DIR/intermixed-lifetime.rs:11:37
99
|
1010
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
1111
| --------------------------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T>`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: lifetime parameters must be declared prior to const parameters
2+
--> $DIR/intermixed-lifetime.rs:7:28
3+
|
4+
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
5+
| -----------------^^---------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
6+
7+
error: type parameters must be declared prior to const parameters
8+
--> $DIR/intermixed-lifetime.rs:7:32
9+
|
10+
LL | struct Foo<const N: usize, 'a, T = u32>(&'a (), T);
11+
| ---------------------^------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
12+
13+
error: lifetime parameters must be declared prior to const parameters
14+
--> $DIR/intermixed-lifetime.rs:11:37
15+
|
16+
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
17+
| --------------------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
18+
19+
error: type parameters must be declared prior to const parameters
20+
--> $DIR/intermixed-lifetime.rs:11:28
21+
|
22+
LL | struct Bar<const N: usize, T = u32, 'a>(&'a (), T);
23+
| -----------------^----------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, T, const N: usize>`
24+
25+
error: aborting due to 4 previous errors
26+
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
// revisions: full min
12
// Checks that lifetimes cannot be interspersed between consts and types.
2-
3-
#![feature(const_generics)]
4-
#![allow(incomplete_features)]
3+
#![cfg_attr(full, feature(const_generics))]
4+
#![cfg_attr(full, allow(incomplete_features))]
5+
#![cfg_attr(min, feature(min_const_generics))]
56

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

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

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

src/test/ui/const-generics/defaults/simple-defaults.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
// run-pass
1+
// [full] run-pass
2+
// revisions: min full
23
// Checks some basic test cases for defaults.
3-
#![feature(const_generics)]
4-
#![allow(incomplete_features)]
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57
#![allow(dead_code)]
68

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

src/test/ui/const-generics/issues/auxiliary/const_generic_issues_lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#![feature(const_generics)]
1+
#![cfg_attr(full, feature(const_generics))]
2+
#![cfg_attr(full, allow(incomplete_features))]
3+
#![cfg_attr(min, feature(min_const_generics))]
24

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

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/issue-61935.rs:10:14
3+
|
4+
LL | Self:FooImpl<{N==0}>
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: generic parameters must not be used inside of non trivial constant values
2+
--> $DIR/issue-61935.rs:10:23
3+
|
4+
LL | Self:FooImpl<{N==0}>
5+
| ^ non-trivial anonymous constants must not depend on the parameter `N`
6+
|
7+
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
8+
9+
error: aborting due to previous error
10+

src/test/ui/const-generics/issues/issue-61935.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// revisions: full min
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(min, feature(min_const_generics))]
35

46
trait Foo {}
57

68
impl<const N: usize> Foo for [(); N]
79
where
810
Self:FooImpl<{N==0}>
9-
//~^ERROR constant expression depends on a generic parameter
11+
//[full]~^ERROR constant expression depends on a generic parameter
12+
//[min]~^^ERROR generic parameters must not be used inside of non trivial constant values
1013
{}
1114

1215
trait FooImpl<const IS_ZERO: bool>{}

src/test/ui/const-generics/issues/issue-61935.stderr

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
22

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
3+
// revisions: full min
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

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

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

src/test/ui/const-generics/issues/issue-62187-encountered-polymorphic-const.stderr

-19
This file was deleted.

src/test/ui/const-generics/issues/issue-62220.stderr src/test/ui/const-generics/issues/issue-62220.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constant expression depends on a generic parameter
2-
--> $DIR/issue-62220.rs:10:27
2+
--> $DIR/issue-62220.rs:13:27
33
|
44
LL | pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: generic parameters must not be used inside of non trivial constant values
2+
--> $DIR/issue-62220.rs:8:59
3+
|
4+
LL | pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
5+
| ^ non-trivial anonymous constants must not depend on the parameter `N`
6+
|
7+
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
8+
9+
error: aborting due to previous error
10+

src/test/ui/const-generics/issues/issue-62220.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
#![allow(incomplete_features)]
2-
#![feature(const_generics)]
1+
// revisions: full min
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(min, feature(min_const_generics))]
35

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

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

811
impl<T, const N: usize> Vector<T, { N }> {
912
/// Drop the last component and return the vector with one fewer dimension.
1013
pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
11-
//~^ ERROR constant expression depends on a generic parameter
14+
//[full]~^ ERROR constant expression depends on a generic parameter
1215
unimplemented!()
1316
}
1417
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/issue-62456.rs:7:20
3+
|
4+
LL | let _ = [0u64; N + 1];
5+
| ^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: generic parameters must not be used inside of non trivial constant values
2+
--> $DIR/issue-62456.rs:7:20
3+
|
4+
LL | let _ = [0u64; N + 1];
5+
| ^ non-trivial anonymous constants must not depend on the parameter `N`
6+
|
7+
= help: it is currently only allowed to use either `N` or `{ N }` as generic constants
8+
9+
error: aborting due to previous error
10+
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// revisions: full min
2+
#![cfg_attr(full, feature(const_generics))]
3+
#![cfg_attr(full, allow(incomplete_features))]
4+
#![cfg_attr(min, feature(min_const_generics))]
35

46
fn foo<const N: usize>() {
57
let _ = [0u64; N + 1];
6-
//~^ ERROR constant expression depends on a generic parameter
8+
//[full]~^ ERROR constant expression depends on a generic parameter
9+
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
710
}
811

912
fn main() {}

src/test/ui/const-generics/issues/issue-62456.stderr

-19
This file was deleted.

src/test/ui/const-generics/issues/issue-62504.stderr src/test/ui/const-generics/issues/issue-62504.full.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constant expression depends on a generic parameter
2-
--> $DIR/issue-62504.rs:18:25
2+
--> $DIR/issue-62504.rs:19:25
33
|
44
LL | ArrayHolder([0; Self::SIZE])
55
| ^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: generic parameters must not be used inside of non trivial constant values
2+
--> $DIR/issue-62504.rs:19:25
3+
|
4+
LL | ArrayHolder([0; Self::SIZE])
5+
| ^^^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `Self`
6+
|
7+
= help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)