@@ -403,10 +403,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
403
403
)
404
404
} ) ;
405
405
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) ;
406
410
hir:: ItemKind :: Impl {
407
411
unsafety : self . lower_unsafety ( unsafety) ,
408
412
polarity,
409
- defaultness : self . lower_defaultness ( defaultness, true /* [1] */ ) ,
413
+ defaultness,
414
+ defaultness_span,
410
415
constness : self . lower_constness ( constness) ,
411
416
generics,
412
417
of_trait : trait_ref,
@@ -435,9 +440,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
435
440
bug ! ( "`TyMac` should have been expanded by now" )
436
441
}
437
442
}
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.
441
443
}
442
444
443
445
fn lower_const_item (
@@ -868,27 +870,31 @@ impl<'hir> LoweringContext<'_, 'hir> {
868
870
AssocItemKind :: MacCall ( ..) => bug ! ( "`TyMac` should have been expanded by now" ) ,
869
871
} ;
870
872
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) ;
871
876
hir:: ImplItem {
872
877
hir_id : self . lower_node_id ( i. id ) ,
873
878
ident : i. ident ,
874
879
attrs : self . lower_attrs ( & i. attrs ) ,
875
880
generics,
876
881
vis : self . lower_visibility ( & i. vis , None ) ,
877
- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
882
+ defaultness,
878
883
kind,
879
884
span : i. span ,
880
885
}
881
-
882
- // [1] since `default impl` is not yet implemented, this is always true in impls
883
886
}
884
887
885
888
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) ;
886
892
hir:: ImplItemRef {
887
893
id : hir:: ImplItemId { hir_id : self . lower_node_id ( i. id ) } ,
888
894
ident : i. ident ,
889
895
span : i. span ,
890
896
vis : self . lower_visibility ( & i. vis , Some ( i. id ) ) ,
891
- defaultness : self . lower_defaultness ( i . kind . defaultness ( ) , true /* [1] */ ) ,
897
+ defaultness,
892
898
kind : match & i. kind {
893
899
AssocItemKind :: Const ( ..) => hir:: AssocItemKind :: Const ,
894
900
AssocItemKind :: TyAlias ( .., ty) => {
@@ -903,8 +909,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
903
909
AssocItemKind :: MacCall ( ..) => unimplemented ! ( ) ,
904
910
} ,
905
911
}
906
-
907
- // [1] since `default impl` is not yet implemented, this is always true in impls
908
912
}
909
913
910
914
/// If an `explicit_owner` is given, this method allocates the `HirId` in
@@ -939,12 +943,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
939
943
respan ( v. span , node)
940
944
}
941
945
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 > ) {
943
951
match d {
944
- Defaultness :: Default ( _ ) => hir:: Defaultness :: Default { has_value } ,
952
+ Defaultness :: Default ( sp ) => ( hir:: Defaultness :: Default { has_value } , Some ( sp ) ) ,
945
953
Defaultness :: Final => {
946
954
assert ! ( has_value) ;
947
- hir:: Defaultness :: Final
955
+ ( hir:: Defaultness :: Final , None )
948
956
}
949
957
}
950
958
}
0 commit comments