Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,16 +482,18 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
) -> Result<(), ErrorGuaranteed> {
let tcx = self.tcx();
let parent_def_id = self.item_def_id();
// In this path, `Some(context)` should be `ConstArgument`: enum
// discriminants are handled earlier by resolve. We still use the helper so
// nested inline consts are checked in the outer const-argument context.
if let Res::Def(DefKind::ConstParam, _) = res
&& matches!(tcx.def_kind(parent_def_id), DefKind::AnonConst | DefKind::InlineConst)
&& let ty::AnonConstKind::MCG = tcx.anon_const_kind(parent_def_id)
&& let Some(context) = self.anon_const_forbids_generic_params()
{
let folder = ForbidParamUsesFolder {
tcx,
anon_const_def_id: parent_def_id,
span,
is_self_alias: false,
context: ForbidParamContext::ConstArgument,
context,
};
return Err(folder.error());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@compile-flags: -Znext-solver=globally
#![feature(generic_const_args, min_generic_const_args)]

struct S<const N: usize>;
fn foo<const N: usize>(_: S<{ const { const { N } } }>) {}
//~^ ERROR: generic parameters in const blocks are not allowed; use a named `const` item instead


fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: generic parameters in const blocks are not allowed; use a named `const` item instead
--> $DIR/const-param-in-nested-inline-const-arg.rs:5:47
|
LL | fn foo<const N: usize>(_: S<{ const { const { N } } }>) {}
| ^
|
= help: consider factoring the expression into a `type const` item and use it as the const argument instead

error: aborting due to 1 previous error

Loading