Skip to content

unify the AST repr of type const and const RHS#159596

Open
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:type-const-rhs-expr
Open

unify the AST repr of type const and const RHS#159596
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:type-const-rhs-expr

Conversation

@khyperia

@khyperia khyperia commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

related to min_generic_const_args, tracking issue here: #132980

Previously, we were parsing/lowering the RHS of type consts differently than regular consts. We no longer need to do so, yippee! This deletes the anon const from the RHS of type consts. This removes the fake defid for the rhs of type consts, FYI.

r? @BoxyUwU

@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

@rustbot rustbot added 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. labels Jul 20, 2026
@rustbot rustbot added the T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. label Jul 20, 2026
@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

Comment on lines -3885 to +3895
self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| match rhs_kind {
ConstItemRhsKind::TypeConst { rhs: Some(anon_const) } => {
this.resolve_anon_const(anon_const, AnonConstKind::ConstArg(IsRepeatExpr::No));
}
ConstItemRhsKind::Body { rhs: Some(expr) } => {
if let Some(body) = body {
self.with_lifetime_rib(LifetimeRibKind::elided(LifetimeRes::Infer), |this| {
this.with_constant_rib(IsRepeatExpr::No, ConstantHasGenerics::Yes, item, |this| {
this.visit_expr(expr)
});
}
_ => (),
})
this.visit_expr(body)
})
})
}

@khyperia khyperia Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is actually a bit subtle/involved change, just want to point it out. Upon repeatedly inlining resolve_anon_const, the old behavior amounted to:

  • type consts: LifetimeRib(infer) { ConstantRib(Generics::Yes, None) { LifetimeRib(Infer) { ... expr ... } } }
  • regular consts: LifetimeRib(infer) { ConstantRib(Generics::Yes, item) { ... expr ... } }

The ConstantRib item argument, AFAIK, is only used for diagnostics, and so it's fine to change it from None->item (seems more correct, anyway). I also removed the duplicate inner LifetimeRib.

View changes since the review

pub rhs_kind: ConstItemRhsKind,
pub body: Option<Box<Expr>>,
#[visitable(ignore)]
pub kind: ConstItemKind,

@khyperia khyperia Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these names are all bikesheddable, fwiw, just kinda kept the names that were there before.

  • body or expr?
  • ConstItemKind::Body or ConstItemKind::Normal? Or Regular or Standard or Plain or...
  • kind or something specific to, like, is_type_const: TypeConstness::{Yes, No}?
  • or just, is_type_const: bool?

View changes since the review

@rust-bors

This comment has been minimized.

@khyperia
khyperia force-pushed the type-const-rhs-expr branch from 867d626 to e895ed8 Compare July 22, 2026 07:26
@rustbot

rustbot commented Jul 22, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants