Skip to content

Conversation

@BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Nov 20, 2025

r? oli-obk

tracking issue: #132980

This PR requires that when feature(min_generic_const_args) is enabled, anon const const args are syntactically distinguishable from other kinds of args. We use const { ... } in const argument position to denote an anon const:

#![feature(min_generic_const_args)]

// no longer allowed as `1 + 1` is represented via an anon const and
// there is no syntactic marker
type Foo = [(); 1 + 1];

// allowed, `const { ... }` indicates an anon const representation
type Foo = [(); const { 1 + 1 }];

This restriction is only placed when mgca is enabled. There should be no effect on stable.

This restriction allows us to create DefIds for anon consts only when actually required. When it is syntactically ambiguous whether a const argument is an anon const or not we are forced to conservatively create a DefId for every const argument even if it doesn't wind up needing one.

This works fine on stable but under mgca we can wind up with anon consts nested inside non-anon-const const arguments resulting in a broken DefId tree. See #148838 where an anon const arg inside of a path arg winds up with a parent of a conservatively created DefId that doesn't actually correspond to an anon const, resulting in an ICE.

With #149114 every field initialiser in a const argument would become a place where there could possibly be an anon const. This would also get worse once we support tuple constructors- now every function argument is a place where there could possibly be an anon const.

We introduce this restriction to avoid creating massive amounts of unused DefIds that make the parent tree significantly more complicated, and to avoid having to paper over this issue in things like generics_of.

Fixes #148838

It also must be syntactically clear from context whether '_ means an inference lifetime or an elided lifetime parameter. This restriction will allow us to properly resolve '_ in const arguments in mgca. This PR doesn't actually fix handle this, but we could do so trivially after this lands.

@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2025

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output. labels Nov 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2025

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

&& let StmtKind::Expr(expr) = &stmt.kind
&& matches!(expr.kind, ExprKind::Path(..) | ExprKind::Struct(..))
{
return self.lower_expr_to_const_arg_direct(expr);
Copy link
Member Author

Choose a reason for hiding this comment

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

I think that this very basic recursive setup means that under mgca we'd now accept {{ N }} and {{{{{{ <T as Trait>::ASSOC }}}}}} and whatnot. ie arbitrary braces surrounding direct args. this seems fine:tm: to me for now

Copy link
Member Author

Choose a reason for hiding this comment

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

tests/ui/const-generics/mgca/multi_braced_direct_const_args.rs

@BoxyUwU BoxyUwU force-pushed the mgca_explicit_anon_consts branch 2 times, most recently from a786e30 to 09d75e3 Compare November 21, 2025 01:38
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU force-pushed the mgca_explicit_anon_consts branch from 09d75e3 to 5c64af2 Compare November 21, 2025 03:53
@rustbot
Copy link
Collaborator

rustbot commented Nov 21, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Nov 21, 2025
@bors
Copy link
Collaborator

bors commented Nov 27, 2025

☔ The latest upstream changes (presumably #149387) made this pull request unmergeable. Please resolve the merge conflicts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. T-rustdoc-frontend Relevant to the rustdoc-frontend team, which will review and decide on the web UI/UX output.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: generics_of: unexpected node kind ConstArg(ConstArg

5 participants