@@ -541,19 +541,14 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
541541 hir:: AssocItemConstraintKind :: Equality { term } => {
542542 let term = match term {
543543 hir:: Term :: Ty ( ty) => self . lower_ty ( ty) . into ( ) ,
544- hir:: Term :: Const ( ct) => {
545- let ty = projection_term. map_bound ( |alias| {
546- tcx. type_of ( alias. def_id ) . instantiate ( tcx, alias. args )
547- } ) ;
548- let ty = check_assoc_const_binding_type (
549- self ,
544+ hir:: Term :: Const ( ct) => self
545+ . lower_assoc_const_binding_rhs (
546+ ct,
550547 constraint. ident ,
551- ty,
552548 constraint. hir_id ,
553- ) ;
554-
555- self . lower_const_arg ( ct, ty) . into ( )
556- }
549+ projection_term,
550+ )
551+ . into ( ) ,
557552 } ;
558553
559554 // Find any late-bound regions declared in `ty` that are not
@@ -853,6 +848,22 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
853848 let shifted_output = tcx. shift_bound_var_indices ( num_bound_vars, output) ;
854849 Ok ( ty:: EarlyBinder :: bind ( shifted_output) . instantiate ( tcx, args) )
855850 }
851+
852+ /// Derives the expected type of an associated const,
853+ /// validates it, and lowers the RHS const arg against that type
854+ pub ( crate ) fn lower_assoc_const_binding_rhs (
855+ & self ,
856+ ct : & ' tcx hir:: ConstArg < ' tcx > ,
857+ assoc_ident : Ident ,
858+ constraint_hir_id : hir:: HirId ,
859+ projection_term : ty:: Binder < ' tcx , ty:: AliasTerm < ' tcx > > ,
860+ ) -> ty:: Const < ' tcx > {
861+ let tcx = self . tcx ( ) ;
862+ let ty = projection_term
863+ . map_bound ( |alias| tcx. type_of ( alias. def_id ) . instantiate ( tcx, alias. args ) ) ;
864+ let ty = check_assoc_const_binding_type ( self , assoc_ident, ty, constraint_hir_id) ;
865+ self . lower_const_arg ( ct, ty)
866+ }
856867}
857868
858869/// Detect and reject early-bound & escaping late-bound generic params in the type of assoc const bindings.
0 commit comments