Skip to content

Commit 7dc3a0c

Browse files
committed
Add feature gate note and test
1 parent 2960124 commit 7dc3a0c

16 files changed

Lines changed: 89 additions & 6 deletions

compiler/rustc_ast_passes/messages.ftl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,6 @@ ast_passes_impl_fn_const =
218218
ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed
219219
.help = remove one of these features
220220
221-
ast_passes_missing_dependent_features = `{$parent}` requires {$missing} to be enabled
222-
.help = enable all of these features
223-
224221
ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier
225222
.suggestion = remove safe from this item
226223
@@ -231,6 +228,9 @@ ast_passes_match_arm_with_no_body =
231228
`match` arm with no body
232229
.suggestion = add a body after the pattern
233230
231+
ast_passes_missing_dependent_features = `{$parent}` requires {$missing} to be enabled
232+
.help = enable all of these features
233+
234234
ast_passes_missing_unsafe_on_extern = extern blocks must be unsafe
235235
.suggestion = needs `unsafe` before the extern keyword
236236

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,11 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
405405
diag.span_note(impl_.self_ty.span, "not a concrete type");
406406
}
407407
}
408+
if self.tcx.features().min_generic_const_args()
409+
&& !self.tcx.features().opaque_generic_const_args()
410+
{
411+
diag.help("add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items");
412+
}
408413
diag.emit()
409414
}
410415
}

tests/ui/const-generics/associated-const-bindings/ambiguity.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: `unsized_const_params` requires `adt_const_params` to be enabled
2+
--> $DIR/ambiguity.rs:4:36
3+
|
4+
LL | #![feature(min_generic_const_args, unsized_const_params)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: enable all of these features
8+
19
error[E0222]: ambiguous associated constant `K` in bounds of `Trait0`
210
--> $DIR/ambiguity.rs:13:25
311
|
@@ -34,6 +42,6 @@ LL | fn take1(_: impl Trait1<C = "?">) {}
3442
T: Parent2::C = "?",
3543
T: Parent1::C = "?"
3644

37-
error: aborting due to 2 previous errors
45+
error: aborting due to 3 previous errors
3846

3947
For more information about this error, try `rustc --explain E0222`.

tests/ui/const-generics/associated-const-bindings/esc-bound-var-in-ty.stderr

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
error: `unsized_const_params` requires `adt_const_params` to be enabled
2+
--> $DIR/esc-bound-var-in-ty.rs:5:5
3+
|
4+
LL | unsized_const_params,
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: enable all of these features
8+
19
error: the type of the associated constant `K` cannot capture late-bound generic parameters
210
--> $DIR/esc-bound-var-in-ty.rs:15:35
311
|
@@ -8,5 +16,5 @@ LL | fn take(_: impl for<'r> Trait<'r, K = const { &() }>) {}
816
|
917
= note: `K` has type `&'r ()`
1018

11-
error: aborting due to 1 previous error
19+
error: aborting due to 2 previous errors
1220

tests/ui/const-generics/mgca/adt_expr_arg_simple.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error: generic parameters may not be used in const operations
99
|
1010
LL | foo::<{ Some::<u32> { 0: const { N + 1 } } }>();
1111
| ^
12+
|
13+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
1214

1315
error: aborting due to 2 previous errors
1416

tests/ui/const-generics/mgca/early-bound-param-lt-bad.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: generic parameters may not be used in const operations
33
|
44
LL | T: Trait<const { let a: &'a (); 1 }>
55
| ^^
6+
|
7+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
68

79
error: aborting due to 1 previous error
810

tests/ui/const-generics/mgca/explicit_anon_consts.stderr

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,42 +39,56 @@ error: generic parameters may not be used in const operations
3939
|
4040
LL | const ITEM3<const N: usize>: usize = const { N };
4141
| ^
42+
|
43+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
4244

4345
error: generic parameters may not be used in const operations
4446
--> $DIR/explicit_anon_consts.rs:60:31
4547
|
4648
LL | T3: Trait<ASSOC = const { N }>,
4749
| ^
50+
|
51+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
4852

4953
error: generic parameters may not be used in const operations
5054
--> $DIR/explicit_anon_consts.rs:69:58
5155
|
5256
LL | struct Default3<const N: usize, const M: usize = const { N }>;
5357
| ^
58+
|
59+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
5460

5561
error: generic parameters may not be used in const operations
5662
--> $DIR/explicit_anon_consts.rs:28:27
5763
|
5864
LL | let _3 = [(); const { N }];
5965
| ^
66+
|
67+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
6068

6169
error: generic parameters may not be used in const operations
6270
--> $DIR/explicit_anon_consts.rs:33:26
6371
|
6472
LL | let _6: [(); const { N }] = todo!();
6573
| ^
74+
|
75+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
6676

6777
error: generic parameters may not be used in const operations
6878
--> $DIR/explicit_anon_consts.rs:11:41
6979
|
7080
LL | type Adt3<const N: usize> = Foo<const { N }>;
7181
| ^
82+
|
83+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
7284

7385
error: generic parameters may not be used in const operations
7486
--> $DIR/explicit_anon_consts.rs:19:42
7587
|
7688
LL | type Arr3<const N: usize> = [(); const { N }];
7789
| ^
90+
|
91+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
7892

7993
error: aborting due to 13 previous errors
8094

tests/ui/const-generics/mgca/selftyalias-containing-param.stderr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ note: not a concrete type
99
|
1010
LL | impl<const N: usize> S<N> {
1111
| ^^^^
12+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
1213

1314
error: aborting due to 1 previous error
1415

tests/ui/const-generics/mgca/selftyparam.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: generic parameters may not be used in const operations
33
|
44
LL | fn foo() -> [(); const { let _: Self; 1 }];
55
| ^^^^
6+
|
7+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
68

79
error: aborting due to 1 previous error
810

tests/ui/const-generics/mgca/tuple_ctor_complex_args.stderr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ error: generic parameters may not be used in const operations
99
|
1010
LL | with_point::<{ Point(const { N + 1 }, N) }>();
1111
| ^
12+
|
13+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
1214

1315
error: aborting due to 2 previous errors
1416

0 commit comments

Comments
 (0)