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
11 changes: 10 additions & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2549,7 +2549,10 @@ impl<'hir> LoweringContext<'_, 'hir> {

let is_trivial_path = path.is_potential_trivial_const_arg()
&& matches!(res, Res::Def(DefKind::ConstParam, _));
let ct_kind = if is_trivial_path || tcx.features().min_generic_const_args() {
let ct_kind = if matches!(res, Res::Def(DefKind::Static { .. }, _)) {
let msg = "complex const arguments must be placed inside of a `const` block";
hir::ConstArgKind::Error(self.dcx().struct_span_err(span, msg).emit())
} else if is_trivial_path || tcx.features().min_generic_const_args() {
let qpath = self.lower_qpath(

@BoxyUwU BoxyUwU Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @khyperia i don't think we handled this codepath in your PR overhauling ast lowering for mgca. we should probably be checking can_lower_to_direct_const_arg here and then also reusing the lower_expr_to_direct logic here? though it would really just be the path arms right now but still... seems nice for consistency/sharing logic 🤔

unrelated to this PR, just something i realised while reading this

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yus, the logic here happens to be identical even with the syntax flip PR, but, it's a very wishy-washy "happens to be correct" and you're absolutely right that these should share a codepath so they don't accidentally diverge

ty_id,
&None,
Expand Down Expand Up @@ -2677,6 +2680,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
ConstArg { hir_id: self.next_id(), kind: hir::ConstArgKind::Tup(exprs), span }
}
ExprKind::Path(qself, path) => {
if let Some(Res::Def(DefKind::Static { .. }, _)) =
self.get_partial_res(expr.id).and_then(|partial_res| partial_res.full_res())
{
return overly_complex_const(self);
}

let qpath = self.lower_qpath(
expr.id,
qself,
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/const-generics/mgca/static-const-arg.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Regression test for #132986.
// FIXME(min_generic_const_args): using statics as direct const arguments should error instead of
// ICEing until const eval can evaluate statics to valtrees for const generics.

#![feature(min_generic_const_args)]
#![allow(incomplete_features)]

static A: u32 = 0;

struct Foo<const N: u32>;

const _: Foo<{ A }> = Foo;
//~^ ERROR complex const arguments must be placed inside of a `const` block

const _: Foo<A> = Foo;
//~^ ERROR complex const arguments must be placed inside of a `const` block

fn main() {}
14 changes: 14 additions & 0 deletions tests/ui/const-generics/mgca/static-const-arg.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: complex const arguments must be placed inside of a `const` block
--> $DIR/static-const-arg.rs:12:16
|
LL | const _: Foo<{ A }> = Foo;
| ^

error: complex const arguments must be placed inside of a `const` block
--> $DIR/static-const-arg.rs:15:14
|
LL | const _: Foo<A> = Foo;
| ^

error: aborting due to 2 previous errors

Loading