@@ -402,10 +402,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
402402 )
403403 } ) ;
404404
405+ // `defaultness.has_value()` is never called for an `impl`, always `true` in order
406+ // to not cause an assertion failure inside the `lower_defaultness` function.
407+ let has_val = true ;
408+ let ( defaultness, defaultness_span) = self . lower_defaultness ( defaultness, has_val) ;
405409 hir:: ItemKind :: Impl {
406410 unsafety : self . lower_unsafety ( unsafety) ,
407411 polarity,
408- defaultness : self . lower_defaultness ( defaultness, true /* [1] */ ) ,
412+ defaultness,
413+ defaultness_span,
409414 constness : self . lower_constness ( constness) ,
410415 generics,
411416 of_trait : trait_ref,
@@ -434,9 +439,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
434439 panic ! ( "`TyMac` should have been expanded by now" )
435440 }
436441 }
437-
438- // [1] `defaultness.has_value()` is never called for an `impl`, always `true` in order to
439- // not cause an assertion failure inside the `lower_defaultness` function.
440442 }
441443
442444 fn lower_const_item (
@@ -867,27 +869,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
867869 AssocItemKind :: MacCall ( ..) => panic ! ( "`TyMac` should have been expanded by now" ) ,
868870 } ;
869871
872+ // Since `default impl` is not yet implemented, this is always true in impls.
873+ let has_value = true ;
874+ let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
870875 hir:: ImplItem {
871876 hir_id : self . lower_node_id ( i. id ) ,
872877 ident : i. ident ,
873878 attrs : self . lower_attrs ( & i. attrs ) ,
874879 generics,
875880 vis : self . lower_visibility ( & i. vis , None ) ,
876- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
881+ defaultness,
877882 kind,
878883 span : i. span ,
879884 }
880-
881- // [1] since `default impl` is not yet implemented, this is always true in impls
882885 }
883886
884887 fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef < ' hir > {
888+ // Since `default impl` is not yet implemented, this is always true in impls.
889+ let has_value = true ;
890+ let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
885891 hir:: ImplItemRef {
886892 id : hir:: ImplItemId { hir_id : self . lower_node_id ( i. id ) } ,
887893 ident : i. ident ,
888894 span : i. span ,
889895 vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
890- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
896+ defaultness,
891897 kind : match & i. kind {
892898 AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
893899 AssocItemKind :: TyAlias ( .., ty) => {
@@ -902,8 +908,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
902908 AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
903909 } ,
904910 }
905-
906- // [1] since `default impl` is not yet implemented, this is always true in impls
907911 }
908912
909913 /// If an `explicit_owner` is given, this method allocates the `HirId` in
@@ -938,12 +942,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
938942 respan ( v. span , node)
939943 }
940944
941- fn lower_defaultness ( & self , d : Defaultness , has_value : bool ) -> hir:: Defaultness {
945+ fn lower_defaultness (
946+ & self ,
947+ d : Defaultness ,
948+ has_value : bool ,
949+ ) -> ( hir:: Defaultness , Option < Span > ) {
942950 match d {
943- Defaultness :: Default ( _ ) => hir:: Defaultness :: Default { has_value } ,
951+ Defaultness :: Default ( sp ) => ( hir:: Defaultness :: Default { has_value } , Some ( sp ) ) ,
944952 Defaultness :: Final => {
945953 assert ! ( has_value) ;
946- hir:: Defaultness :: Final
954+ ( hir:: Defaultness :: Final , None )
947955 }
948956 }
949957 }
0 commit comments