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