@@ -341,7 +341,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
341341 // lifetime to be added, but rather a reference to a
342342 // parent lifetime.
343343 let itctx = ImplTraitContext :: Universal ;
344- // TODO we need to rip apart this infrastructure
345344 let ( generics, ( trait_ref, lowered_ty) ) =
346345 self . lower_generics ( ast_generics, Const :: No , id, & itctx, |this| {
347346 let trait_ref = trait_ref. as_ref ( ) . map ( |trait_ref| {
@@ -576,30 +575,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
576575 // This is used to track which lifetimes have already been defined,
577576 // and which need to be replicated when lowering an async fn.
578577
579- let generics = match parent_hir. node ( ) . expect_item ( ) . kind {
578+ let parent_item = parent_hir. node ( ) . expect_item ( ) ;
579+ let constness = match parent_item. kind {
580580 hir:: ItemKind :: Impl ( impl_) => {
581581 self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
582- & impl_. generics
582+ match impl_. constness {
583+ // TODO bad span
584+ hir:: Constness :: Const => Const :: Yes ( impl_. self_ty . span ) ,
585+ hir:: Constness :: NotConst => Const :: No ,
586+ }
583587 }
584- hir:: ItemKind :: Trait ( _, _, generics, _, _) => generics,
588+ hir:: ItemKind :: Trait ( _, _, _, _, _) => {
589+ parent_hir. attrs . get ( parent_item. hir_id ( ) . local_id ) . iter ( ) . find ( |attr| attr. has_name ( sym:: const_trait) ) . map_or ( Const :: No , |attr| Const :: Yes ( attr. span ) )
590+ } ,
585591 kind => {
586592 span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
587593 }
588594 } ;
589595
590- if self . tcx . features ( ) . effects {
591- self . host_param_id = generics
592- . params
593- . iter ( )
594- . find ( |param| {
595- matches ! ( param. kind, hir:: GenericParamKind :: Const { is_host_effect: true , .. } )
596- } )
597- . map ( |param| param. def_id ) ;
598- }
599-
600596 match ctxt {
601- AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
602- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
597+ AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item, constness ) ) ,
598+ AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item, constness ) ) ,
603599 }
604600 }
605601
@@ -726,7 +722,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
726722 }
727723 }
728724
729- fn lower_trait_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: TraitItem < ' hir > {
725+ fn lower_trait_item ( & mut self , i : & AssocItem , trait_constness : Const ) -> & ' hir hir:: TraitItem < ' hir > {
730726 let hir_id = self . lower_node_id ( i. id ) ;
731727 self . lower_attrs ( hir_id, & i. attrs ) ;
732728 let trait_item_def_id = hir_id. expect_owner ( ) ;
@@ -758,6 +754,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
758754 i. id ,
759755 FnDeclKind :: Trait ,
760756 sig. header . coroutine_kind ,
757+ trait_constness,
761758 ) ;
762759 ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) , false )
763760 }
@@ -775,6 +772,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
775772 i. id ,
776773 FnDeclKind :: Trait ,
777774 sig. header . coroutine_kind ,
775+ trait_constness,
778776 ) ;
779777 ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) , true )
780778 }
@@ -852,7 +850,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
852850 self . expr ( span, hir:: ExprKind :: Err ( guar) )
853851 }
854852
855- fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
853+ fn lower_impl_item ( & mut self , i : & AssocItem , impl_constness : Const ) -> & ' hir hir:: ImplItem < ' hir > {
856854 // Since `default impl` is not yet implemented, this is always true in impls.
857855 let has_value = true ;
858856 let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
@@ -887,6 +885,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
887885 i. id ,
888886 if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
889887 sig. header . coroutine_kind ,
888+ impl_constness,
890889 ) ;
891890
892891 ( generics, hir:: ImplItemKind :: Fn ( sig, body_id) )
@@ -1300,11 +1299,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
13001299 id : NodeId ,
13011300 kind : FnDeclKind ,
13021301 coroutine_kind : Option < CoroutineKind > ,
1302+ parent_constness : Const ,
13031303 ) -> ( & ' hir hir:: Generics < ' hir > , hir:: FnSig < ' hir > ) {
13041304 let header = self . lower_fn_header ( sig. header ) ;
13051305 // Don't pass along the user-provided constness of trait associated functions; we don't want to
13061306 // synthesize a host effect param for them. We reject `const` on them during AST validation.
1307- let constness = if kind == FnDeclKind :: Inherent { sig. header . constness } else { Const :: No } ;
1307+ let constness = if kind == FnDeclKind :: Inherent { sig. header . constness } else { parent_constness } ;
13081308 let itctx = ImplTraitContext :: Universal ;
13091309 let ( generics, decl) = self . lower_generics ( generics, constness, id, & itctx, |this| {
13101310 this. lower_fn_decl ( & sig. decl , id, sig. span , kind, coroutine_kind)
0 commit comments