@@ -333,10 +333,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
333333 let res = if free. kind ( infcx. tcx ) . is_type ( ) {
334334 infcx. tcx . type_of ( free. def_id ) . instantiate ( infcx. tcx , free. args ) . fold_with ( self ) . into ( )
335335 } else {
336- // FIXME(mgca): once const items are actual aliases defined as equal to type system consts
337- // this should instead use that rather than evaluating.
338- super :: evaluate_const ( infcx, free. to_term ( infcx. tcx ) . expect_const ( ) , self . param_env )
339- . super_fold_with ( self )
336+ infcx
337+ . tcx
338+ . const_of_item ( free. def_id )
339+ . instantiate ( infcx. tcx , free. args )
340+ . fold_with ( self )
340341 . into ( )
341342 } ;
342343 self . depth -= 1 ;
@@ -436,51 +437,47 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
436437 return ct;
437438 }
438439
439- // Doing "proper" normalization of const aliases is inherently cyclic until const items
440- // are real aliases instead of having bodies. We gate proper const alias handling behind
441- // mgca to avoid breaking stable code, though this should become the "main" codepath long
442- // before mgca is stabilized.
440+ let uv = match ct. kind ( ) {
441+ ty:: ConstKind :: Unevaluated ( uv) => uv,
442+ _ => return ct. super_fold_with ( self ) ,
443+ } ;
444+
445+ // Note that the AssocConst and Const cases are unreachable on stable,
446+ // unless a `min_generic_const_args` feature gate error has already
447+ // been emitted earlier in compilation.
443448 //
444- // FIXME(BoxyUwU): Enabling this by default is blocked on a refactoring to how const items
445- // are represented.
446- if tcx. features ( ) . min_generic_const_args ( ) {
447- let uv = match ct. kind ( ) {
448- ty:: ConstKind :: Unevaluated ( uv) => uv,
449- _ => return ct. super_fold_with ( self ) ,
450- } ;
451-
452- let ct = match tcx. def_kind ( uv. def ) {
453- DefKind :: AssocConst => match tcx. def_kind ( tcx. parent ( uv. def ) ) {
454- DefKind :: Trait => self . normalize_trait_projection ( uv. into ( ) ) ,
455- DefKind :: Impl { of_trait : false } => {
456- self . normalize_inherent_projection ( uv. into ( ) )
457- }
458- kind => unreachable ! (
459- "unexpected `DefKind` for const alias' resolution's parent def: {:?}" ,
460- kind
461- ) ,
462- } ,
463- DefKind :: Const | DefKind :: AnonConst => self . normalize_free_alias ( uv. into ( ) ) ,
464- kind => {
465- unreachable ! ( "unexpected `DefKind` for const alias to resolve to: {:?}" , kind)
449+ // That's because we can only end up with an Unevaluated ty::Const for a const item
450+ // if it was marked with `#[type_const]`. Using this attribute without the mgca
451+ // feature gate causes a parse error.
452+ let ct = match tcx. def_kind ( uv. def ) {
453+ DefKind :: AssocConst => match tcx. def_kind ( tcx. parent ( uv. def ) ) {
454+ DefKind :: Trait => self . normalize_trait_projection ( uv. into ( ) ) . expect_const ( ) ,
455+ DefKind :: Impl { of_trait : false } => {
456+ self . normalize_inherent_projection ( uv. into ( ) ) . expect_const ( )
466457 }
467- } ;
458+ kind => unreachable ! (
459+ "unexpected `DefKind` for const alias' resolution's parent def: {:?}" ,
460+ kind
461+ ) ,
462+ } ,
463+ DefKind :: Const => self . normalize_free_alias ( uv. into ( ) ) . expect_const ( ) ,
464+ DefKind :: AnonConst => {
465+ let ct = ct. super_fold_with ( self ) ;
466+ super :: with_replaced_escaping_bound_vars (
467+ self . selcx . infcx ,
468+ & mut self . universes ,
469+ ct,
470+ |ct| super :: evaluate_const ( self . selcx . infcx , ct, self . param_env ) ,
471+ )
472+ }
473+ kind => {
474+ unreachable ! ( "unexpected `DefKind` for const alias to resolve to: {:?}" , kind)
475+ }
476+ } ;
468477
469- // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
470- // unnormalized after const evaluation returns.
471- ct. expect_const ( ) . super_fold_with ( self )
472- } else {
473- let ct = ct. super_fold_with ( self ) ;
474- return super :: with_replaced_escaping_bound_vars (
475- self . selcx . infcx ,
476- & mut self . universes ,
477- ct,
478- |ct| super :: evaluate_const ( self . selcx . infcx , ct, self . param_env ) ,
479- )
480- . super_fold_with ( self ) ;
481- // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
482- // unnormalized after const evaluation returns.
483- }
478+ // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
479+ // unnormalized after const evaluation returns.
480+ ct. super_fold_with ( self )
484481 }
485482
486483 #[ inline]
0 commit comments