Remove hir::ArrayLen, introduce ConstArgKind::Infer

Remove Node::ArrayLenInfer
This commit is contained in:
Dominik Stolz 2024-11-28 17:33:22 +01:00
parent 9b4d7c6a40
commit d38f01312c
24 changed files with 105 additions and 182 deletions

View file

@ -1277,9 +1277,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}),
))
}
TyKind::Array(ty, length) => {
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_array_length(length))
}
TyKind::Array(ty, length) => hir::TyKind::Array(
self.lower_ty(ty, itctx),
self.lower_array_length_to_const_arg(length),
),
TyKind::Typeof(expr) => hir::TyKind::Typeof(self.lower_anon_const_to_anon_const(expr)),
TyKind::TraitObject(bounds, kind) => {
let mut lifetime_bound = None;
@ -2029,14 +2030,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.expr_block(block)
}
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen<'hir> {
fn lower_array_length_to_const_arg(&mut self, c: &AnonConst) -> &'hir hir::ConstArg<'hir> {
match c.value.kind {
ExprKind::Underscore => {
if self.tcx.features().generic_arg_infer() {
hir::ArrayLen::Infer(hir::InferArg {
hir_id: self.lower_node_id(c.id),
span: self.lower_span(c.value.span),
})
let ct_kind = hir::ConstArgKind::Infer(self.lower_span(c.value.span));
self.arena.alloc(hir::ConstArg { hir_id: self.next_id(), kind: ct_kind })
} else {
feature_err(
&self.tcx.sess,
@ -2045,10 +2044,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fluent_generated::ast_lowering_underscore_array_length_unstable,
)
.stash(c.value.span, StashKey::UnderscoreForArrayLengths);
hir::ArrayLen::Body(self.lower_anon_const_to_const_arg(c))
self.lower_anon_const_to_const_arg(c)
}
}
_ => hir::ArrayLen::Body(self.lower_anon_const_to_const_arg(c)),
_ => self.lower_anon_const_to_const_arg(c),
}
}