Skip to content

Commit 9bf40f1

Browse files
committed
Add missing tests in root const-gen dir
1 parent be650a7 commit 9bf40f1

File tree

83 files changed

+1182
-102
lines changed

Some content is hidden

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

83 files changed

+1182
-102
lines changed

src/test/ui/const-generics/apit-with-const-param.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// check-pass
2+
// revisions: full min
23

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

68
trait Trait {}
79

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: constant expression depends on a generic parameter
2+
--> $DIR/array-size-in-generic-struct-param.rs:9:38
3+
|
4+
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
5+
| ^^^^^^^^^^^^
6+
|
7+
= note: this may fail depending on what value the parameter takes
8+
9+
error: constant expression depends on a generic parameter
10+
--> $DIR/array-size-in-generic-struct-param.rs:20:10
11+
|
12+
LL | arr: [u8; CFG.arr_size],
13+
| ^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: this may fail depending on what value the parameter takes
16+
17+
error: aborting due to 2 previous errors
18+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error: generic parameters must not be used inside of non trivial constant values
2+
--> $DIR/array-size-in-generic-struct-param.rs:9:48
3+
|
4+
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
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: generic parameters must not be used inside of non trivial constant values
10+
--> $DIR/array-size-in-generic-struct-param.rs:20:15
11+
|
12+
LL | arr: [u8; CFG.arr_size],
13+
| ^^^ non-trivial anonymous constants must not depend on the parameter `CFG`
14+
|
15+
= help: it is currently only allowed to use either `CFG` or `{ CFG }` as generic constants
16+
17+
error: using `Config` as const generic parameters is forbidden
18+
--> $DIR/array-size-in-generic-struct-param.rs:18:21
19+
|
20+
LL | struct B<const CFG: Config> {
21+
| ^^^^^^
22+
|
23+
= note: the only supported types are integers, `bool` and `char`
24+
= note: more complex types are supported with `#[feature(const_generics)]`
25+
26+
error: aborting due to 3 previous errors
27+

src/test/ui/const-generics/array-size-in-generic-struct-param.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
1-
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete
1+
// Tests that array sizes that depend on const-params does not yet work.
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
37

48
#[allow(dead_code)]
59
struct ArithArrayLen<const N: usize>([u32; 0 + N]);
6-
//~^ ERROR constant expression depends on a generic parameter
10+
//[full]~^ ERROR constant expression depends on a generic parameter
11+
//[min]~^^ ERROR generic parameters must not be used inside of non trivial constant values
712

813
#[derive(PartialEq, Eq)]
914
struct Config {
1015
arr_size: usize,
1116
}
1217

1318
struct B<const CFG: Config> {
14-
arr: [u8; CFG.arr_size], //~ ERROR constant expression depends on a generic parameter
19+
//[min]~^ ERROR using `Config` as const generic parameters is forbidden
20+
arr: [u8; CFG.arr_size],
21+
//[full]~^ ERROR constant expression depends on a generic parameter
22+
//[min]~^^ ERROR generic parameters must not be used inside of non trivial
1523
}
1624

1725
const C: Config = Config { arr_size: 5 };

src/test/ui/const-generics/broken-mir-1.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

3-
#![feature(const_generics)]
4-
//~^ WARN the feature `const_generics` is incomplete
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 Foo {
79
fn foo(&self);

src/test/ui/const-generics/broken-mir-2.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

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

68
use std::fmt::Debug;
79

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/cannot-infer-const-args.rs:12:5
3+
|
4+
LL | foo();
5+
| ^^^
6+
|
7+
= note: unable to infer the value of a const parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/cannot-infer-const-args.rs:12:5
3+
|
4+
LL | foo();
5+
| ^^^
6+
|
7+
= note: unable to infer the value of a const parameter
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

src/test/ui/const-generics/cannot-infer-const-args.rs

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

47
fn foo<const X: usize>() -> usize {
58
0

src/test/ui/const-generics/coerce_unsized_array.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// run-pass
2-
#![feature(const_generics)]
3-
#![allow(incomplete_features)]
2+
// revisions: full min
3+
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
47

58
fn foo<const N: usize>(v: &[u8; N]) -> &[u8] {
69
v

src/test/ui/const-generics/concrete-const-as-fn-arg.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Test that a concrete const type i.e. A<2>, can be used as an argument type in a function
22
// run-pass
3+
// revisions: full min
34

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

79
struct A<const N: usize>; // ok
810

src/test/ui/const-generics/concrete-const-impl-method.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
// Test that a method/associated non-method within an impl block of a concrete const type i.e. A<2>,
22
// is callable.
33
// run-pass
4+
// revisions: full min
45

5-
#![feature(const_generics)]
6-
//~^ WARN the feature `const_generics` is incomplete
6+
#![cfg_attr(full, feature(const_generics))]
7+
#![cfg_attr(full, allow(incomplete_features))]
8+
#![cfg_attr(min, feature(min_const_generics))]
79

810
pub struct A<const N: u32>;
911

src/test/ui/const-generics/condition-in-trait-const-arg.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// Checks whether conditions in traits can be evaluated.
12
// run-pass
3+
// revisions: full min
24

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

69
trait IsZeroTrait<const IS_ZERO: bool>{}
710

src/test/ui/const-generics/const-arg-in-fn.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
// Check that const args in functions can be used.
12
// run-pass
3+
// revisions: full min
24

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

69
fn const_u32_identity<const X: u32>() -> u32 {
710
X

src/test/ui/const-generics/const-argument-non-static-lifetime.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full
3+
// FIXME Omitted min revision for now due to ICE.
24

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

79
fn test<const N: usize>() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `,` or `>`, found `+`
2+
--> $DIR/const-expression-parameter.rs:16:22
3+
|
4+
LL | i32_identity::<1 + 2>();
5+
| ^ expected one of `,` or `>`
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `,` or `>`, found `+`
2+
--> $DIR/const-expression-parameter.rs:16:22
3+
|
4+
LL | i32_identity::<1 + 2>();
5+
| ^ expected one of `,` or `>`
6+
7+
error: aborting due to previous error
8+

src/test/ui/const-generics/const-expression-parameter.rs

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

47
fn i32_identity<const X: i32>() -> i32 {
58
5

src/test/ui/const-generics/const-fn-with-const-param.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
// Check `const fn` with const param is alright
12
// run-pass
2-
#![feature(const_generics)]
3-
//~^ WARN the feature `const_generics` is incomplete
3+
// revisions: full min
4+
5+
#![cfg_attr(full, feature(const_generics))]
6+
#![cfg_attr(full, allow(incomplete_features))]
7+
#![cfg_attr(min, feature(min_const_generics))]
48

59
const fn const_u32_identity<const X: u32>() -> u32 {
610
X

src/test/ui/const-generics/const-generic-array-wrapper.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

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

68
struct Foo<T, const N: usize>([T; N]);
79

src/test/ui/const-generics/const-generic-type_name.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// run-pass
2+
// revisions: full min
23

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

68
#[derive(Debug)]
79
struct S<const N: usize>;

src/test/ui/const-generics/const-param-after-const-literal-arg.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// check-pass
2+
// revisions: full min
23

3-
#![allow(incomplete_features)]
4-
#![feature(const_generics)]
4+
#![cfg_attr(full, feature(const_generics))]
5+
#![cfg_attr(full, allow(incomplete_features))]
6+
#![cfg_attr(min, feature(min_const_generics))]
57

68
struct Foo<const A: usize, const B: usize>;
79

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0637]: `&` without an explicit lifetime name cannot be used here
2+
--> $DIR/const-param-elided-lifetime.rs:11:19
3+
|
4+
LL | struct A<const N: &u8>;
5+
| ^ explicit lifetime name needed here
6+
7+
error[E0637]: `&` without an explicit lifetime name cannot be used here
8+
--> $DIR/const-param-elided-lifetime.rs:16:15
9+
|
10+
LL | impl<const N: &u8> A<N> {
11+
| ^ explicit lifetime name needed here
12+
13+
error[E0637]: `&` without an explicit lifetime name cannot be used here
14+
--> $DIR/const-param-elided-lifetime.rs:19:21
15+
|
16+
LL | fn foo<const M: &u8>(&self) {}
17+
| ^ explicit lifetime name needed here
18+
19+
error[E0637]: `&` without an explicit lifetime name cannot be used here
20+
--> $DIR/const-param-elided-lifetime.rs:24:15
21+
|
22+
LL | impl<const N: &u8> B for A<N> {}
23+
| ^ explicit lifetime name needed here
24+
25+
error[E0637]: `&` without an explicit lifetime name cannot be used here
26+
--> $DIR/const-param-elided-lifetime.rs:28:17
27+
|
28+
LL | fn bar<const N: &u8>() {}
29+
| ^ explicit lifetime name needed here
30+
31+
error: aborting due to 5 previous errors
32+
33+
For more information about this error, try `rustc --explain E0637`.

0 commit comments

Comments
 (0)