@@ -403,10 +403,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
403403 )
404404 } ) ;
405405
406+ // `defaultness.has_value()` is never called for an `impl`, always `true` in order
407+ // to not cause an assertion failure inside the `lower_defaultness` function.
408+ let has_val = true ;
409+ let ( defaultness, defaultness_span) = self . lower_defaultness ( defaultness, has_val) ;
406410 hir:: ItemKind :: Impl {
407411 unsafety : self . lower_unsafety ( unsafety) ,
408412 polarity,
409- defaultness : self . lower_defaultness ( defaultness, true /* [1] */ ) ,
413+ defaultness,
414+ defaultness_span,
410415 constness : self . lower_constness ( constness) ,
411416 generics,
412417 of_trait : trait_ref,
@@ -435,9 +440,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
435440 bug ! ( "`TyMac` should have been expanded by now" )
436441 }
437442 }
438-
439- // [1] `defaultness.has_value()` is never called for an `impl`, always `true` in order to
440- // not cause an assertion failure inside the `lower_defaultness` function.
441443 }
442444
443445 fn lower_const_item (
@@ -868,27 +870,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
868870 AssocItemKind :: MacCall ( ..) => bug ! ( "`TyMac` should have been expanded by now" ) ,
869871 } ;
870872
873+ // Since `default impl` is not yet implemented, this is always true in impls.
874+ let has_value = true ;
875+ let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
871876 hir:: ImplItem {
872877 hir_id : self . lower_node_id ( i. id ) ,
873878 ident : i. ident ,
874879 attrs : self . lower_attrs ( & i. attrs ) ,
875880 generics,
876881 vis : self . lower_visibility ( & i. vis , None ) ,
877- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
882+ defaultness,
878883 kind,
879884 span : i. span ,
880885 }
881-
882- // [1] since `default impl` is not yet implemented, this is always true in impls
883886 }
884887
885888 fn lower_impl_item_ref ( & mut self , i : & AssocItem ) -> hir:: ImplItemRef < ' hir > {
889+ // Since `default impl` is not yet implemented, this is always true in impls.
890+ let has_value = true ;
891+ let ( defaultness, _) = self . lower_defaultness ( i. kind . defaultness ( ) , has_value) ;
886892 hir:: ImplItemRef {
887893 id : hir:: ImplItemId { hir_id : self . lower_node_id ( i. id ) } ,
888894 ident : i. ident ,
889895 span : i. span ,
890896 vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
891- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
897+ defaultness,
892898 kind : match & i. kind {
893899 AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
894900 AssocItemKind :: TyAlias ( .., ty) => {
@@ -903,8 +909,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
903909 AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
904910 } ,
905911 }
906-
907- // [1] since `default impl` is not yet implemented, this is always true in impls
908912 }
909913
910914 /// If an `explicit_owner` is given, this method allocates the `HirId` in
@@ -939,12 +943,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
939943 respan ( v. span , node)
940944 }
941945
942- fn lower_defaultness ( & self , d : Defaultness , has_value : bool ) -> hir:: Defaultness {
946+ fn lower_defaultness (
947+ & self ,
948+ d : Defaultness ,
949+ has_value : bool ,
950+ ) -> ( hir:: Defaultness , Option < Span > ) {
943951 match d {
944- Defaultness :: Default ( _ ) => hir:: Defaultness :: Default { has_value } ,
952+ Defaultness :: Default ( sp ) => ( hir:: Defaultness :: Default { has_value } , Some ( sp ) ) ,
945953 Defaultness :: Final => {
946954 assert ! ( has_value) ;
947- hir:: Defaultness :: Final
955+ ( hir:: Defaultness :: Final , None )
948956 }
949957 }
950958 }
0 commit comments