unify the AST repr of type const and const RHS#159596
Conversation
|
cc @rust-lang/clippy The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease
cc @rust-lang/rustfmt |
|
|
| 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) | ||
| }) | ||
| }) | ||
| } |
There was a problem hiding this comment.
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.
| pub rhs_kind: ConstItemRhsKind, | ||
| pub body: Option<Box<Expr>>, | ||
| #[visitable(ignore)] | ||
| pub kind: ConstItemKind, |
There was a problem hiding this comment.
these names are all bikesheddable, fwiw, just kinda kept the names that were there before.
bodyorexpr?ConstItemKind::BodyorConstItemKind::Normal? Or Regular or Standard or Plain or...kindor something specific to, like,is_type_const: TypeConstness::{Yes, No}?- or just,
is_type_const: bool?
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
merge conflicts with #159058 - please prioritize that one first :3
the weird test changes are due to weird error handling fallback when using
type constwithout#![feature(min_generic_const_args)]- the test differences go away once #159058 is merged (which lowers the rhs of type consts as if#![feature(mgca)]was enabled, even if it isn't, to suppress these weird double errors). fun fact, the line of code causing the merge conflict is exactly this change, to lower the rhs as if mgca is unconditionally enabled ✨