@@ -341,7 +341,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
341
341
// lifetime to be added, but rather a reference to a
342
342
// parent lifetime.
343
343
let itctx = ImplTraitContext :: Universal ;
344
- // TODO we need to rip apart this infrastructure
345
344
let ( generics, ( trait_ref, lowered_ty) ) =
346
345
self . lower_generics ( ast_generics, Const :: No , id, & itctx, |this| {
347
346
let trait_ref = trait_ref. as_ref ( ) . map ( |trait_ref| {
@@ -576,30 +575,27 @@ impl<'hir> LoweringContext<'_, 'hir> {
576
575
// This is used to track which lifetimes have already been defined,
577
576
// and which need to be replicated when lowering an async fn.
578
577
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 {
580
580
hir:: ItemKind :: Impl ( impl_) => {
581
581
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
+ }
583
587
}
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
+ } ,
585
591
kind => {
586
592
span_bug ! ( item. span, "assoc item has unexpected kind of parent: {}" , kind. descr( ) )
587
593
}
588
594
} ;
589
595
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
-
600
596
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 ) ) ,
603
599
}
604
600
}
605
601
@@ -726,7 +722,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
726
722
}
727
723
}
728
724
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 > {
730
726
let hir_id = self . lower_node_id ( i. id ) ;
731
727
self . lower_attrs ( hir_id, & i. attrs ) ;
732
728
let trait_item_def_id = hir_id. expect_owner ( ) ;
@@ -758,6 +754,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
758
754
i. id ,
759
755
FnDeclKind :: Trait ,
760
756
sig. header . coroutine_kind ,
757
+ trait_constness,
761
758
) ;
762
759
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) , false )
763
760
}
@@ -775,6 +772,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
775
772
i. id ,
776
773
FnDeclKind :: Trait ,
777
774
sig. header . coroutine_kind ,
775
+ trait_constness,
778
776
) ;
779
777
( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) , true )
780
778
}
@@ -852,7 +850,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
852
850
self . expr ( span, hir:: ExprKind :: Err ( guar) )
853
851
}
854
852
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 > {
856
854
// Since `default impl` is not yet implemented, this is always true in impls.
857
855
let has_value = true ;
858
856
let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
@@ -887,6 +885,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
887
885
i. id ,
888
886
if self . is_in_trait_impl { FnDeclKind :: Impl } else { FnDeclKind :: Inherent } ,
889
887
sig. header . coroutine_kind ,
888
+ impl_constness,
890
889
) ;
891
890
892
891
( generics, hir:: ImplItemKind :: Fn ( sig, body_id) )
@@ -1300,11 +1299,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
1300
1299
id : NodeId ,
1301
1300
kind : FnDeclKind ,
1302
1301
coroutine_kind : Option < CoroutineKind > ,
1302
+ parent_constness : Const ,
1303
1303
) -> ( & ' hir hir:: Generics < ' hir > , hir:: FnSig < ' hir > ) {
1304
1304
let header = self . lower_fn_header ( sig. header ) ;
1305
1305
// Don't pass along the user-provided constness of trait associated functions; we don't want to
1306
1306
// 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 } ;
1308
1308
let itctx = ImplTraitContext :: Universal ;
1309
1309
let ( generics, decl) = self . lower_generics ( generics, constness, id, & itctx, |this| {
1310
1310
this. lower_fn_decl ( & sig. decl , id, sig. span , kind, coroutine_kind)
0 commit comments