@@ -231,9 +231,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
231231 let ( ty, body_id) = self . lower_const_item ( t, span, e. as_deref ( ) ) ;
232232 hir:: ItemKind :: Static ( ty, * m, body_id)
233233 }
234- ItemKind :: Const ( box ast:: ConstItem { ty, expr, .. } ) => {
235- let ( ty, body_id) = self . lower_const_item ( ty, span, expr. as_deref ( ) ) ;
236- hir:: ItemKind :: Const ( ty, body_id)
234+ ItemKind :: Const ( box ast:: ConstItem { generics, ty, expr, .. } ) => {
235+ let ( generics, ( ty, body_id) ) = self . lower_generics (
236+ generics,
237+ Const :: No ,
238+ id,
239+ & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
240+ |this| this. lower_const_item ( ty, span, expr. as_deref ( ) ) ,
241+ ) ;
242+ hir:: ItemKind :: Const ( ty, generics, body_id)
237243 }
238244 ItemKind :: Fn ( box Fn {
239245 sig : FnSig { decl, header, span : fn_sig_span } ,
@@ -723,11 +729,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
723729 let trait_item_def_id = hir_id. expect_owner ( ) ;
724730
725731 let ( generics, kind, has_default) = match & i. kind {
726- AssocItemKind :: Const ( box ConstItem { ty, expr, .. } ) => {
727- let ty =
728- self . lower_ty ( ty, & ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
729- let body = expr. as_ref ( ) . map ( |x| self . lower_const_body ( i. span , Some ( x) ) ) ;
730- ( hir:: Generics :: empty ( ) , hir:: TraitItemKind :: Const ( ty, body) , body. is_some ( ) )
732+ AssocItemKind :: Const ( box ConstItem { generics, ty, expr, .. } ) => {
733+ let ( generics, kind) = self . lower_generics (
734+ & generics,
735+ Const :: No ,
736+ i. id ,
737+ & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
738+ |this| {
739+ let ty = this. lower_ty (
740+ ty,
741+ // FIXME(generic_consts): Should we create `AssocConstTy` and use it here?
742+ & ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ,
743+ ) ;
744+ let body = expr. as_ref ( ) . map ( |x| this. lower_const_body ( i. span , Some ( x) ) ) ;
745+
746+ hir:: TraitItemKind :: Const ( ty, body)
747+ } ,
748+ ) ;
749+ ( generics, kind, expr. is_some ( ) )
731750 }
732751 AssocItemKind :: Fn ( box Fn { sig, generics, body : None , .. } ) => {
733752 let asyncness = sig. header . asyncness ;
@@ -825,14 +844,19 @@ impl<'hir> LoweringContext<'_, 'hir> {
825844 self . lower_attrs ( hir_id, & i. attrs ) ;
826845
827846 let ( generics, kind) = match & i. kind {
828- AssocItemKind :: Const ( box ConstItem { ty, expr, .. } ) => {
829- let ty =
830- self . lower_ty ( ty, & ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
831- (
832- hir:: Generics :: empty ( ) ,
833- hir:: ImplItemKind :: Const ( ty, self . lower_const_body ( i. span , expr. as_deref ( ) ) ) ,
834- )
835- }
847+ AssocItemKind :: Const ( box ConstItem { generics, ty, expr, .. } ) => self . lower_generics (
848+ & generics,
849+ Const :: No ,
850+ i. id ,
851+ & ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
852+ |this| {
853+ let ty = this
854+ . lower_ty ( ty, & ImplTraitContext :: Disallowed ( ImplTraitPosition :: ConstTy ) ) ;
855+ let body = this. lower_const_body ( i. span , expr. as_deref ( ) ) ;
856+
857+ hir:: ImplItemKind :: Const ( ty, body)
858+ } ,
859+ ) ,
836860 AssocItemKind :: Fn ( box Fn { sig, generics, body, .. } ) => {
837861 self . current_item = Some ( i. span ) ;
838862 let asyncness = sig. header . asyncness ;
0 commit comments