@@ -338,7 +338,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
338
338
// lifetime to be added, but rather a reference to a
339
339
// parent lifetime.
340
340
let itctx = ImplTraitContext :: Universal ;
341
- // TODO we need to rip apart this infrastructure
342
341
let ( generics, ( trait_ref, lowered_ty) ) =
343
342
self . lower_generics ( ast_generics, Const :: No , id, itctx, |this| {
344
343
let modifiers = TraitBoundModifiers {
@@ -592,30 +591,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
592
591
// This is used to track which lifetimes have already been defined,
593
592
// and which need to be replicated when lowering an async fn.
594
593
595
- let generics = match parent_hir. node ( ) . expect_item ( ) . kind {
594
+ let parent_item = parent_hir. node ( ) . expect_item ( ) ;
595
+ let constness = match parent_item. kind {
596
596
hir:: ItemKind :: Impl ( impl_) => {
597
597
self . is_in_trait_impl = impl_. of_trait . is_some ( ) ;
598
- & impl_. generics
598
+ match impl_. constness {
599
+ // TODO bad span
600
+ hir:: Constness :: Const => Const :: Yes ( impl_. self_ty . span ) ,
601
+ hir:: Constness :: NotConst => Const :: No ,
602
+ }
599
603
}
600
- hir:: ItemKind :: Trait ( _, _, generics, _, _) => generics,
604
+ hir:: ItemKind :: Trait ( _, _, _, _, _) => {
605
+ 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 ) )
606
+ } ,
601
607
kind => {
602
608
span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
603
609
}
604
610
} ;
605
611
606
- if self . tcx . features ( ) . effects {
607
- self . host_param_id = generics
608
- . params
609
- . iter ( )
610
- . find ( |param| {
611
- matches ! ( param. kind, hir:: GenericParamKind :: Const { is_host_effect: true , .. } )
612
- } )
613
- . map ( |param| param. def_id ) ;
614
- }
615
-
616
612
match ctxt {
617
- AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item) ) ,
618
- AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item) ) ,
613
+ AssocCtxt :: Trait => hir:: OwnerNode :: TraitItem ( self . lower_trait_item ( item, constness ) ) ,
614
+ AssocCtxt :: Impl => hir:: OwnerNode :: ImplItem ( self . lower_impl_item ( item, constness ) ) ,
619
615
}
620
616
}
621
617
@@ -745,7 +741,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
745
741
}
746
742
}
747
743
748
- fn lower_trait_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: TraitItem < ' hir > {
744
+ fn lower_trait_item ( & mut self , i : & AssocItem , trait_constness : Const ) -> & ' hir hir:: TraitItem < ' hir > {
749
745
let hir_id = self . lower_node_id ( i. id ) ;
750
746
self . lower_attrs ( hir_id, & i. attrs ) ;
751
747
let trait_item_def_id = hir_id. expect_owner ( ) ;
@@ -775,6 +771,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
775
771
i. id ,
776
772
FnDeclKind :: Trait ,
777
773
sig. header . coroutine_kind ,
774
+ trait_constness,
778
775
) ;
779
776
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) , false )
780
777
}
@@ -792,6 +789,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
792
789
i. id ,
793
790
FnDeclKind :: Trait ,
794
791
sig. header . coroutine_kind ,
792
+ trait_constness,
795
793
) ;
796
794
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) , true )
797
795
}
@@ -869,7 +867,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
869
867
self . expr ( span, hir:: ExprKind :: Err ( guar) )
870
868
}
871
869
872
- fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
870
+ fn lower_impl_item ( & mut self , i : & AssocItem , impl_constness : Const ) -> & ' hir hir:: ImplItem < ' hir > {
873
871
// Since `default impl` is not yet implemented, this is always true in impls.
874
872
let has_value = true ;
875
873
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
@@ -904,6 +902,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
904
902
i. id ,
905
903
if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
906
904
sig. header . coroutine_kind ,
905
+ impl_constness,
907
906
) ;
908
907
909
908
( generics, hir:: ImplItemKind :: Fn ( sig, body_id) )
@@ -1316,11 +1315,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1316
1315
id : NodeId ,
1317
1316
kind : FnDeclKind ,
1318
1317
coroutine_kind : Option < CoroutineKind > ,
1318
+ parent_constness : Const ,
1319
1319
) -> ( & ' hir hir:: Generics < ' hir > , hir:: FnSig < ' hir > ) {
1320
1320
let header = self . lower_fn_header ( sig. header ) ;
1321
1321
// Don't pass along the user-provided constness of trait associated functions; we don't want to
1322
1322
// synthesize a host effect param for them. We reject `const` on them during AST validation.
1323
- let constness = if kind == FnDeclKind :: Inherent { sig. header . constness } else { Const :: No } ;
1323
+ let constness = if kind == FnDeclKind :: Inherent { sig. header . constness } else { parent_constness } ;
1324
1324
let itctx = ImplTraitContext :: Universal ;
1325
1325
let ( generics, decl) = self . lower_generics ( generics, constness, id, itctx, |this| {
1326
1326
this. lower_fn_decl ( & sig. decl , id, sig. span , kind, coroutine_kind)
0 commit comments