Skip to content

Commit f049b0b

Browse files
Rollup merge of rust-lang#79374 - mendess:const-param-expr-diagnostic, r=lcnr
Add note to use nightly when using expr in const generics As recommended by `@Icnr` in rust-lang#73899 and in zulip, I've added a note saying that const expressions can be used in nightly. ``` error: generic parameters may not be used in const operations --> $DIR/issue-61935.rs:10:23 | 6 | Self:FooImpl<{N==0}> | ^ cannot perform const operation using `N` | = help: const parameters may only be used as standalone arguments, i.e. `N` = note: use feature(const_generics) and feature(const_evaluatable_checked) to enable this error: aborting due to previous error ``` I hope the note is well written :sweat_smile:
2 parents 95e7af3 + 888055e commit f049b0b

File tree

56 files changed

+113
-54
lines changed

Some content is hidden

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

56 files changed

+113
-54
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ impl<'a> Resolver<'a> {
481481
name
482482
));
483483
}
484+
err.help("use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions");
484485

485486
err
486487
}

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
329329
),
330330
)
331331
.note("the only supported types are integers, `bool` and `char`")
332-
.note("more complex types are supported with `#[feature(const_generics)]`")
332+
.help("more complex types are supported with `#[feature(const_generics)]`")
333333
.emit()
334334
}
335335
};

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/array-size-in-generic-struct-param.rs:20:15
@@ -13,6 +14,7 @@ LL | arr: [u8; CFG.arr_size],
1314
| ^^^ cannot perform const operation using `CFG`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `CFG`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: `Config` is forbidden as the type of a const generic parameter
1820
--> $DIR/array-size-in-generic-struct-param.rs:18:21
@@ -21,7 +23,7 @@ LL | struct B<const CFG: Config> {
2123
| ^^^^^^
2224
|
2325
= note: the only supported types are integers, `bool` and `char`
24-
= note: more complex types are supported with `#[feature(const_generics)]`
26+
= help: more complex types are supported with `#[feature(const_generics)]`
2527

2628
error: aborting due to 3 previous errors
2729

src/test/ui/const-generics/const-arg-in-const-arg.min.stderr

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let _: [u8; foo::<T>()];
55
| ^ cannot perform const operation using `T`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/const-arg-in-const-arg.rs:15:23
@@ -13,6 +14,7 @@ LL | let _: [u8; bar::<N>()];
1314
| ^ cannot perform const operation using `N`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `N`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: generic parameters may not be used in const operations
1820
--> $DIR/const-arg-in-const-arg.rs:25:23
@@ -21,6 +23,7 @@ LL | let _ = [0; bar::<N>()];
2123
| ^ cannot perform const operation using `N`
2224
|
2325
= help: const parameters may only be used as standalone arguments, i.e. `N`
26+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
2427

2528
error: generic parameters may not be used in const operations
2629
--> $DIR/const-arg-in-const-arg.rs:30:24
@@ -29,6 +32,7 @@ LL | let _: Foo<{ foo::<T>() }>;
2932
| ^ cannot perform const operation using `T`
3033
|
3134
= note: type parameters may not be used in const expressions
35+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
3236

3337
error: generic parameters may not be used in const operations
3438
--> $DIR/const-arg-in-const-arg.rs:31:24
@@ -37,6 +41,7 @@ LL | let _: Foo<{ bar::<N>() }>;
3741
| ^ cannot perform const operation using `N`
3842
|
3943
= help: const parameters may only be used as standalone arguments, i.e. `N`
44+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
4045

4146
error: generic parameters may not be used in const operations
4247
--> $DIR/const-arg-in-const-arg.rs:36:27
@@ -45,6 +50,7 @@ LL | let _ = Foo::<{ foo::<T>() }>;
4550
| ^ cannot perform const operation using `T`
4651
|
4752
= note: type parameters may not be used in const expressions
53+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
4854

4955
error: generic parameters may not be used in const operations
5056
--> $DIR/const-arg-in-const-arg.rs:37:27
@@ -53,6 +59,7 @@ LL | let _ = Foo::<{ bar::<N>() }>;
5359
| ^ cannot perform const operation using `N`
5460
|
5561
= help: const parameters may only be used as standalone arguments, i.e. `N`
62+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
5663

5764
error[E0658]: a non-static lifetime is not allowed in a `const`
5865
--> $DIR/const-arg-in-const-arg.rs:16:23

src/test/ui/const-generics/const-argument-if-length.min.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | pad: [u8; is_zst::<T>()],
55
| ^ cannot perform const operation using `T`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error[E0277]: the size for values of type `T` cannot be known at compilation time
1011
--> $DIR/const-argument-if-length.rs:17:12

src/test/ui/const-generics/const-param-before-other-params.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | fn bar<const X: (), 'a>(_: &'a ()) {
1717
| ^^
1818
|
1919
= note: the only supported types are integers, `bool` and `char`
20-
= note: more complex types are supported with `#[feature(const_generics)]`
20+
= help: more complex types are supported with `#[feature(const_generics)]`
2121

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

3131
error: aborting due to 4 previous errors
3232

src/test/ui/const-generics/const-param-elided-lifetime.min.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ LL | struct A<const N: &u8>;
3535
| ^^^
3636
|
3737
= note: the only supported types are integers, `bool` and `char`
38-
= note: more complex types are supported with `#[feature(const_generics)]`
38+
= help: more complex types are supported with `#[feature(const_generics)]`
3939

4040
error: `&'static u8` is forbidden as the type of a const generic parameter
4141
--> $DIR/const-param-elided-lifetime.rs:16:15
@@ -44,7 +44,7 @@ LL | impl<const N: &u8> A<N> {
4444
| ^^^
4545
|
4646
= note: the only supported types are integers, `bool` and `char`
47-
= note: more complex types are supported with `#[feature(const_generics)]`
47+
= help: more complex types are supported with `#[feature(const_generics)]`
4848

4949
error: `&'static u8` is forbidden as the type of a const generic parameter
5050
--> $DIR/const-param-elided-lifetime.rs:24:15
@@ -53,7 +53,7 @@ LL | impl<const N: &u8> B for A<N> {}
5353
| ^^^
5454
|
5555
= note: the only supported types are integers, `bool` and `char`
56-
= note: more complex types are supported with `#[feature(const_generics)]`
56+
= help: more complex types are supported with `#[feature(const_generics)]`
5757

5858
error: `&'static u8` is forbidden as the type of a const generic parameter
5959
--> $DIR/const-param-elided-lifetime.rs:28:17
@@ -62,7 +62,7 @@ LL | fn bar<const N: &u8>() {}
6262
| ^^^
6363
|
6464
= note: the only supported types are integers, `bool` and `char`
65-
= note: more complex types are supported with `#[feature(const_generics)]`
65+
= help: more complex types are supported with `#[feature(const_generics)]`
6666

6767
error: `&'static u8` is forbidden as the type of a const generic parameter
6868
--> $DIR/const-param-elided-lifetime.rs:19:21
@@ -71,7 +71,7 @@ LL | fn foo<const M: &u8>(&self) {}
7171
| ^^^
7272
|
7373
= note: the only supported types are integers, `bool` and `char`
74-
= note: more complex types are supported with `#[feature(const_generics)]`
74+
= help: more complex types are supported with `#[feature(const_generics)]`
7575

7676
error: aborting due to 10 previous errors
7777

src/test/ui/const-generics/const-param-type-depends-on-const-param.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LL | pub struct Dependent<const N: usize, const X: [u8; N]>([(); N]);
1717
| ^^^^^^^
1818
|
1919
= note: the only supported types are integers, `bool` and `char`
20-
= note: more complex types are supported with `#[feature(const_generics)]`
20+
= help: more complex types are supported with `#[feature(const_generics)]`
2121

2222
error: `[u8; _]` is forbidden as the type of a const generic parameter
2323
--> $DIR/const-param-type-depends-on-const-param.rs:16:35
@@ -26,7 +26,7 @@ LL | pub struct SelfDependent<const N: [u8; N]>;
2626
| ^^^^^^^
2727
|
2828
= note: the only supported types are integers, `bool` and `char`
29-
= note: more complex types are supported with `#[feature(const_generics)]`
29+
= help: more complex types are supported with `#[feature(const_generics)]`
3030

3131
error: aborting due to 4 previous errors
3232

src/test/ui/const-generics/const_evaluatable_checked/feature-gate-const_evaluatable_checked.min.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | type Arr<const N: usize> = [u8; N - 1];
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

src/test/ui/const-generics/const_evaluatable_checked/simple.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/simple.rs:8:35
@@ -13,6 +14,7 @@ LL | fn test<const N: usize>() -> [u8; N - 1] where [u8; N - 1]: Default {
1314
| ^ cannot perform const operation using `N`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `N`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: aborting due to 2 previous errors
1820

src/test/ui/const-generics/const_evaluatable_checked/simple_fail.min.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | type Arr<const N: usize> = [u8; N - 1];
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

src/test/ui/const-generics/different_byref.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct Const<const V: [usize; 1]> {}
55
| ^^^^^^^^^^
66
|
77
= note: the only supported types are integers, `bool` and `char`
8-
= note: more complex types are supported with `#[feature(const_generics)]`
8+
= help: more complex types are supported with `#[feature(const_generics)]`
99

1010
error: aborting due to previous error
1111

src/test/ui/const-generics/forbid-non-structural_match-types.min.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | struct B<const X: A>; // ok
55
| ^
66
|
77
= note: the only supported types are integers, `bool` and `char`
8-
= note: more complex types are supported with `#[feature(const_generics)]`
8+
= help: more complex types are supported with `#[feature(const_generics)]`
99

1010
error: `C` is forbidden as the type of a const generic parameter
1111
--> $DIR/forbid-non-structural_match-types.rs:15:19
@@ -14,7 +14,7 @@ LL | struct D<const X: C>;
1414
| ^
1515
|
1616
= note: the only supported types are integers, `bool` and `char`
17-
= note: more complex types are supported with `#[feature(const_generics)]`
17+
= help: more complex types are supported with `#[feature(const_generics)]`
1818

1919
error[E0741]: `C` must be annotated with `#[derive(PartialEq, Eq)]` to be used as the type of a const parameter
2020
--> $DIR/forbid-non-structural_match-types.rs:15:19

src/test/ui/const-generics/generic-function-call-in-array-length.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | fn bar<const N: usize>() -> [u32; foo(N)] {
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/generic-function-call-in-array-length.rs:12:13
@@ -13,6 +14,7 @@ LL | [0; foo(N)]
1314
| ^ cannot perform const operation using `N`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `N`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: aborting due to 2 previous errors
1820

src/test/ui/const-generics/generic-sum-in-array-length.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {}
55
| ^ cannot perform const operation using `A`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `A`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/generic-sum-in-array-length.rs:7:57
@@ -13,6 +14,7 @@ LL | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {}
1314
| ^ cannot perform const operation using `B`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `B`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: aborting due to 2 previous errors
1820

src/test/ui/const-generics/intrinsics-type_name-as-const-argument.min.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | T: Trait<{std::intrinsics::type_name::<T>()}>
55
| ^ cannot perform const operation using `T`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: `&'static str` is forbidden as the type of a const generic parameter
1011
--> $DIR/intrinsics-type_name-as-const-argument.rs:10:22
@@ -13,7 +14,7 @@ LL | trait Trait<const S: &'static str> {}
1314
| ^^^^^^^^^^^^
1415
|
1516
= note: the only supported types are integers, `bool` and `char`
16-
= note: more complex types are supported with `#[feature(const_generics)]`
17+
= help: more complex types are supported with `#[feature(const_generics)]`
1718

1819
error: aborting due to 2 previous errors
1920

src/test/ui/const-generics/issue-61522-array-len-succ.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | pub struct MyArray<const COUNT: usize>([u8; COUNT + 1]);
55
| ^^^^^ cannot perform const operation using `COUNT`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `COUNT`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/issue-61522-array-len-succ.rs:12:30
@@ -13,6 +14,7 @@ LL | fn inner(&self) -> &[u8; COUNT + 1] {
1314
| ^^^^^ cannot perform const operation using `COUNT`
1415
|
1516
= help: const parameters may only be used as standalone arguments, i.e. `COUNT`
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error: aborting due to 2 previous errors
1820

src/test/ui/const-generics/issue-66596-impl-trait-for-str-const-arg.min.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | trait Trait<const NAME: &'static str> {
55
| ^^^^^^^^^^^^
66
|
77
= note: the only supported types are integers, `bool` and `char`
8-
= note: more complex types are supported with `#[feature(const_generics)]`
8+
= help: more complex types are supported with `#[feature(const_generics)]`
99

1010
error: aborting due to previous error
1111

src/test/ui/const-generics/issue-67375.min.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | inner: [(); { [|_: &T| {}; 0].len() }],
55
| ^ cannot perform const operation using `T`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error[E0392]: parameter `T` is never used
1011
--> $DIR/issue-67375.rs:7:12

src/test/ui/const-generics/issue-67945-1.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let x: S = MaybeUninit::uninit();
55
| ^ cannot perform const operation using `S`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/issue-67945-1.rs:17:45
@@ -13,6 +14,7 @@ LL | let b = &*(&x as *const _ as *const S);
1314
| ^ cannot perform const operation using `S`
1415
|
1516
= note: type parameters may not be used in const expressions
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error[E0392]: parameter `S` is never used
1820
--> $DIR/issue-67945-1.rs:11:12

src/test/ui/const-generics/issue-67945-2.min.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let x: S = MaybeUninit::uninit();
55
| ^ cannot perform const operation using `S`
66
|
77
= note: type parameters may not be used in const expressions
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: generic parameters may not be used in const operations
1011
--> $DIR/issue-67945-2.rs:15:45
@@ -13,6 +14,7 @@ LL | let b = &*(&x as *const _ as *const S);
1314
| ^ cannot perform const operation using `S`
1415
|
1516
= note: type parameters may not be used in const expressions
17+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
1618

1719
error[E0392]: parameter `S` is never used
1820
--> $DIR/issue-67945-2.rs:9:12

src/test/ui/const-generics/issues/issue-61747.min.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | fn successor() -> Const<{C + 1}> {
55
| ^ cannot perform const operation using `C`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `C`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

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

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | Self:FooImpl<{N==0}>
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

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

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

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

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ LL | let _ = [0u64; N + 1];
55
| ^ cannot perform const operation using `N`
66
|
77
= help: const parameters may only be used as standalone arguments, i.e. `N`
8+
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
89

910
error: aborting due to previous error
1011

0 commit comments

Comments
 (0)