@@ -755,17 +755,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
755
755
let hir_id = self . lower_node_id ( i. id ) ;
756
756
let trait_item_def_id = hir_id. expect_owner ( ) ;
757
757
758
- let ( generics, kind) = match i. kind {
758
+ let ( generics, kind, has_default ) = match i. kind {
759
759
AssocItemKind :: Const ( _, ref ty, ref default) => {
760
760
let ty = self . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Type ) ) ;
761
761
let body = default. as_ref ( ) . map ( |x| self . lower_const_body ( i. span , Some ( x) ) ) ;
762
- ( hir:: Generics :: empty ( ) , hir:: TraitItemKind :: Const ( ty, body) )
762
+ ( hir:: Generics :: empty ( ) , hir:: TraitItemKind :: Const ( ty, body) , body . is_some ( ) )
763
763
}
764
764
AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : None , .. } ) => {
765
765
let names = self . lower_fn_params_to_names ( & sig. decl ) ;
766
766
let ( generics, sig) =
767
767
self . lower_method_sig ( generics, sig, i. id , FnDeclKind :: Trait , None ) ;
768
- ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) )
768
+ ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Required ( names) ) , false )
769
769
}
770
770
AssocItemKind :: Fn ( box Fn { ref sig, ref generics, body : Some ( ref body) , .. } ) => {
771
771
let asyncness = sig. header . asyncness ;
@@ -778,7 +778,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
778
778
FnDeclKind :: Trait ,
779
779
asyncness. opt_return_id ( ) ,
780
780
) ;
781
- ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) )
781
+ ( generics, hir:: TraitItemKind :: Fn ( sig, hir:: TraitFn :: Provided ( body_id) ) , true )
782
782
}
783
783
AssocItemKind :: TyAlias ( box TyAlias {
784
784
ref generics,
@@ -789,7 +789,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
789
789
} ) => {
790
790
let mut generics = generics. clone ( ) ;
791
791
add_ty_alias_where_clause ( & mut generics, where_clauses, false ) ;
792
- self . lower_generics (
792
+ let ( generics , kind ) = self . lower_generics (
793
793
& generics,
794
794
i. id ,
795
795
ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
@@ -805,7 +805,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
805
805
ty,
806
806
)
807
807
} ,
808
- )
808
+ ) ;
809
+ ( generics, kind, ty. is_some ( ) )
809
810
}
810
811
AssocItemKind :: MacCall ( ..) => panic ! ( "macro item shouldn't exist at this point" ) ,
811
812
} ;
@@ -817,28 +818,25 @@ impl<'hir> LoweringContext<'_, 'hir> {
817
818
generics,
818
819
kind,
819
820
span : self . lower_span ( i. span ) ,
821
+ defaultness : hir:: Defaultness :: Default { has_value : has_default } ,
820
822
} ;
821
823
self . arena . alloc ( item)
822
824
}
823
825
824
826
fn lower_trait_item_ref ( & mut self , i : & AssocItem ) -> hir:: TraitItemRef {
825
- let ( kind, has_default) = match & i. kind {
826
- AssocItemKind :: Const ( _, _, default) => ( hir:: AssocItemKind :: Const , default. is_some ( ) ) ,
827
- AssocItemKind :: TyAlias ( box TyAlias { ty, .. } ) => {
828
- ( hir:: AssocItemKind :: Type , ty. is_some ( ) )
829
- }
830
- AssocItemKind :: Fn ( box Fn { sig, body, .. } ) => {
831
- ( hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) } , body. is_some ( ) )
827
+ let kind = match & i. kind {
828
+ AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
829
+ AssocItemKind :: TyAlias ( ..) => hir:: AssocItemKind :: Type ,
830
+ AssocItemKind :: Fn ( box Fn { sig, .. } ) => {
831
+ hir:: AssocItemKind :: Fn { has_self : sig. decl . has_self ( ) }
832
832
}
833
833
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
834
834
} ;
835
835
let id = hir:: TraitItemId { def_id : self . local_def_id ( i. id ) } ;
836
- let defaultness = hir:: Defaultness :: Default { has_value : has_default } ;
837
836
hir:: TraitItemRef {
838
837
id,
839
838
ident : self . lower_ident ( i. ident ) ,
840
839
span : self . lower_span ( i. span ) ,
841
- defaultness,
842
840
kind,
843
841
}
844
842
}
@@ -849,6 +847,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
849
847
}
850
848
851
849
fn lower_impl_item ( & mut self , i : & AssocItem ) -> & ' hir hir:: ImplItem < ' hir > {
850
+ // Since `default impl` is not yet implemented, this is always true in impls.
851
+ let has_value = true ;
852
+ let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
853
+
852
854
let ( generics, kind) = match & i. kind {
853
855
AssocItemKind :: Const ( _, ty, expr) => {
854
856
let ty = self . lower_ty ( ty, ImplTraitContext :: Disallowed ( ImplTraitPosition :: Type ) ) ;
@@ -903,19 +905,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
903
905
kind,
904
906
vis_span : self . lower_span ( i. vis . span ) ,
905
907
span : self . lower_span ( i. span ) ,
908
+ defaultness,
906
909
} ;
907
910
self . arena . alloc ( item)
908
911
}
909
912
910
913
fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef {
911
- // Since `default impl` is not yet implemented, this is always true in impls.
912
- let has_value = true ;
913
- let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
914
914
hir:: ImplItemRef {
915
915
id : hir:: ImplItemId { def_id : self . local_def_id ( i. id ) } ,
916
916
ident : self . lower_ident ( i. ident ) ,
917
917
span : self . lower_span ( i. span ) ,
918
- defaultness,
919
918
kind : match & i. kind {
920
919
AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
921
920
AssocItemKind :: TyAlias ( ..) => hir:: AssocItemKind :: Type ,
0 commit comments