Skip to content

Commit ab7be4e

Browse files
committed
Add feature gate note and test
1 parent 3a19397 commit ab7be4e

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ impl<'tcx> ForbidMCGParamUsesFolder<'tcx> {
433433
diag.span_note(impl_.self_ty.span, "not a concrete type");
434434
}
435435
}
436+
if !self.tcx.features().opaque_generic_const_args() {
437+
diag.help("add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items");
438+
}
436439
diag.emit()
437440
}
438441
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(generic_const_items, min_generic_const_args)]
2+
#![expect(incomplete_features)]
3+
4+
#[type_const]
5+
const INC<const N: usize>: usize = const { N + 1 };
6+
//~^ ERROR generic parameters may not be used in const operations
7+
//~| HELP add `#![feature(opaque_generic_const_args)]`
8+
9+
fn main() {}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: generic parameters may not be used in const operations
2+
--> $DIR/feature-gate-opaque-generic-const-args.rs:5:44
3+
|
4+
LL | const INC<const N: usize>: usize = const { N + 1 };
5+
| ^
6+
|
7+
= help: add `#![feature(opaque_generic_const_args)]` to allow generic expressions as the RHS of const items
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)