1
Fork 0

mgca: Lower all const paths as ConstArgKind::Path

When `#![feature(min_generic_const_args)]` is enabled, we now lower all
const paths in generic arg position to `hir::ConstArgKind::Path`. We
then lower assoc const paths to `ty::ConstKind::Unevaluated` since we
can no longer use the anon const expression lowering machinery. In the
process of implementing this, I factored out `hir_ty_lowering` code that
is now shared between lowering assoc types and assoc consts.

This PR also introduces a `#[type_const]` attribute for trait assoc
consts that are allowed as const args. However, we still need to
implement code to check that assoc const definitions satisfy
`#[type_const]` if present (basically is it a const path or a
monomorphic anon const).
This commit is contained in:
Noah Lev 2025-01-06 21:15:56 -08:00
parent 2010bba886
commit 177e7ff548
35 changed files with 602 additions and 148 deletions

View file

@ -1202,7 +1202,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
if let TyKind::Path(None, ref path) = ty.kind
// We cannot disambiguate multi-segment paths right now as that requires type
// checking.
&& path.is_potential_trivial_const_arg()
&& path.is_potential_trivial_const_arg(false)
{
let mut check_ns = |ns| {
self.maybe_resolve_ident_in_lexical_scope(path.segments[0].ident, ns)
@ -4630,11 +4630,12 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
constant, anon_const_kind
);
self.resolve_anon_const_manual(
constant.value.is_potential_trivial_const_arg(),
anon_const_kind,
|this| this.resolve_expr(&constant.value, None),
)
let is_trivial_const_arg = constant
.value
.is_potential_trivial_const_arg(self.r.tcx.features().min_generic_const_args());
self.resolve_anon_const_manual(is_trivial_const_arg, anon_const_kind, |this| {
this.resolve_expr(&constant.value, None)
})
}
/// There are a few places that we need to resolve an anon const but we did not parse an
@ -4794,8 +4795,11 @@ impl<'a, 'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
// Constant arguments need to be treated as AnonConst since
// that is how they will be later lowered to HIR.
if const_args.contains(&idx) {
let is_trivial_const_arg = argument.is_potential_trivial_const_arg(
self.r.tcx.features().min_generic_const_args(),
);
self.resolve_anon_const_manual(
argument.is_potential_trivial_const_arg(),
is_trivial_const_arg,
AnonConstKind::ConstArg(IsRepeatExpr::No),
|this| this.resolve_expr(argument, None),
);