@@ -284,7 +284,6 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
284284 }
285285 }
286286
287- // FIXME(mgca): While this supports constants, it is only used for types by default right now
288287 #[ instrument( level = "debug" , skip( self ) , ret) ]
289288 fn normalize_free_alias ( & mut self , free : AliasTerm < ' tcx > ) -> Term < ' tcx > {
290289 let recursion_limit = self . cx ( ) . recursion_limit ( ) ;
@@ -324,10 +323,11 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
324323 let res = if free. kind ( infcx. tcx ) . is_type ( ) {
325324 infcx. tcx . type_of ( free. def_id ) . instantiate ( infcx. tcx , free. args ) . fold_with ( self ) . into ( )
326325 } else {
327- // FIXME(mgca): once const items are actual aliases defined as equal to type system consts
328- // this should instead use that rather than evaluating.
329- super :: evaluate_const ( infcx, free. to_term ( infcx. tcx ) . expect_const ( ) , self . param_env )
330- . super_fold_with ( self )
326+ infcx
327+ . tcx
328+ . const_of_item ( free. def_id )
329+ . instantiate ( infcx. tcx , free. args )
330+ . fold_with ( self )
331331 . into ( )
332332 } ;
333333 self . depth -= 1 ;
@@ -427,51 +427,38 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
427427 return ct;
428428 }
429429
430- // Doing "proper" normalization of const aliases is inherently cyclic until const items
431- // are real aliases instead of having bodies. We gate proper const alias handling behind
432- // mgca to avoid breaking stable code, though this should become the "main" codepath long
433- // before mgca is stabilized.
434- //
435- // FIXME(BoxyUwU): Enabling this by default is blocked on a refactoring to how const items
436- // are represented.
437- if tcx. features ( ) . min_generic_const_args ( ) {
438- let uv = match ct. kind ( ) {
439- ty:: ConstKind :: Unevaluated ( uv) => uv,
440- _ => return ct. super_fold_with ( self ) ,
441- } ;
442-
443- let ct = match tcx. def_kind ( uv. def ) {
444- DefKind :: AssocConst => match tcx. def_kind ( tcx. parent ( uv. def ) ) {
445- DefKind :: Trait => self . normalize_trait_projection ( uv. into ( ) ) ,
446- DefKind :: Impl { of_trait : false } => {
447- self . normalize_inherent_projection ( uv. into ( ) )
448- }
449- kind => unreachable ! (
450- "unexpected `DefKind` for const alias' resolution's parent def: {:?}" ,
451- kind
452- ) ,
453- } ,
454- DefKind :: Const | DefKind :: AnonConst => self . normalize_free_alias ( uv. into ( ) ) ,
455- kind => {
456- unreachable ! ( "unexpected `DefKind` for const alias to resolve to: {:?}" , kind)
457- }
458- } ;
430+ let uv = match ct. kind ( ) {
431+ ty:: ConstKind :: Unevaluated ( uv) => uv,
432+ _ => return ct. super_fold_with ( self ) ,
433+ } ;
459434
460- // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
461- // unnormalized after const evaluation returns.
462- ct. expect_const ( ) . super_fold_with ( self )
463- } else {
464- let ct = ct. super_fold_with ( self ) ;
465- return super :: with_replaced_escaping_bound_vars (
466- self . selcx . infcx ,
467- & mut self . universes ,
468- ct,
469- |ct| super :: evaluate_const ( self . selcx . infcx , ct, self . param_env ) ,
470- )
471- . super_fold_with ( self ) ;
472- // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
473- // unnormalized after const evaluation returns.
474- }
435+ let ct = match tcx. def_kind ( uv. def ) {
436+ DefKind :: AssocConst => match tcx. def_kind ( tcx. parent ( uv. def ) ) {
437+ DefKind :: Trait => self . normalize_trait_projection ( uv. into ( ) ) . expect_const ( ) ,
438+ DefKind :: Impl { of_trait : false } => self . normalize_inherent_projection ( uv. into ( ) ) . expect_const ( ) ,
439+ kind => unreachable ! (
440+ "unexpected `DefKind` for const alias' resolution's parent def: {:?}" ,
441+ kind
442+ ) ,
443+ } ,
444+ DefKind :: Const => self . normalize_free_alias ( uv. into ( ) ) . expect_const ( ) ,
445+ DefKind :: AnonConst => {
446+ let ct = ct. super_fold_with ( self ) ;
447+ super :: with_replaced_escaping_bound_vars (
448+ self . selcx . infcx ,
449+ & mut self . universes ,
450+ ct,
451+ |ct| super :: evaluate_const ( self . selcx . infcx , ct, self . param_env ) ,
452+ )
453+ }
454+ kind => {
455+ unreachable ! ( "unexpected `DefKind` for const alias to resolve to: {:?}" , kind)
456+ }
457+ } ;
458+
459+ // We re-fold the normalized const as the `ty` field on `ConstKind::Value` may be
460+ // unnormalized after const evaluation returns.
461+ ct. super_fold_with ( self )
475462 }
476463
477464 #[ inline]
0 commit comments