@@ -530,46 +530,33 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
530
530
}
531
531
DefKind :: Fn => { } // entirely within check_item_body
532
532
DefKind :: Impl { of_trait } => {
533
- if of_trait {
534
- let it = tcx. hir ( ) . item ( id) ;
535
- let hir:: ItemKind :: Impl ( impl_) = it. kind else { return } ;
536
- debug ! ( "ItemKind::Impl {} with id {:?}" , it. ident, it. owner_id) ;
537
- if let Some ( impl_trait_ref) = tcx. impl_trait_ref ( it. owner_id ) {
538
- check_impl_items_against_trait (
539
- tcx,
540
- it. span ,
541
- it. owner_id . def_id ,
542
- impl_trait_ref. subst_identity ( ) ,
543
- & impl_. items ,
544
- ) ;
545
- check_on_unimplemented ( tcx, it) ;
546
- }
533
+ if of_trait && let Some ( impl_trait_ref) = tcx. impl_trait_ref ( id. owner_id ) {
534
+ check_impl_items_against_trait (
535
+ tcx,
536
+ id. owner_id . def_id ,
537
+ impl_trait_ref. subst_identity ( ) ,
538
+ ) ;
539
+ check_on_unimplemented ( tcx, id) ;
547
540
}
548
541
}
549
542
DefKind :: Trait => {
550
- let it = tcx. hir ( ) . item ( id) ;
551
- let hir:: ItemKind :: Trait ( _, _, _, _, items) = it. kind else {
552
- return ;
553
- } ;
554
- check_on_unimplemented ( tcx, it) ;
555
-
556
- for item in items. iter ( ) {
557
- let item = tcx. hir ( ) . trait_item ( item. id ) ;
558
- match & item. kind {
559
- hir:: TraitItemKind :: Fn ( sig, _) => {
560
- let abi = sig. header . abi ;
561
- fn_maybe_err ( tcx, item. ident . span , abi) ;
543
+ let assoc_items = tcx. associated_items ( id. owner_id ) ;
544
+ check_on_unimplemented ( tcx, id) ;
545
+
546
+ for assoc_item in assoc_items. in_definition_order ( ) {
547
+ match assoc_item. kind {
548
+ ty:: AssocKind :: Fn => {
549
+ let abi = tcx. fn_sig ( assoc_item. def_id ) . skip_binder ( ) . abi ( ) ;
550
+ fn_maybe_err ( tcx, assoc_item. ident ( tcx) . span , abi) ;
562
551
}
563
- hir:: TraitItemKind :: Type ( .., Some ( default) ) => {
564
- let assoc_item = tcx. associated_item ( item. owner_id ) ;
552
+ ty:: AssocKind :: Type if assoc_item. defaultness ( tcx) . has_value ( ) => {
565
553
let trait_substs =
566
- InternalSubsts :: identity_for_item ( tcx, it . owner_id . to_def_id ( ) ) ;
554
+ InternalSubsts :: identity_for_item ( tcx, id . owner_id . to_def_id ( ) ) ;
567
555
let _: Result < _ , rustc_errors:: ErrorGuaranteed > = check_type_bounds (
568
556
tcx,
569
557
assoc_item,
570
558
assoc_item,
571
- default. span ,
572
- tcx. mk_trait_ref ( it. owner_id . to_def_id ( ) , trait_substs) ,
559
+ tcx. mk_trait_ref ( id. owner_id . to_def_id ( ) , trait_substs) ,
573
560
) ;
574
561
}
575
562
_ => { }
@@ -681,7 +668,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
681
668
}
682
669
}
683
670
684
- pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , item : & hir:: Item < ' _ > ) {
671
+ pub ( super ) fn check_on_unimplemented ( tcx : TyCtxt < ' _ > , item : hir:: ItemId ) {
685
672
// an error would be reported if this fails.
686
673
let _ = OnUnimplementedDirective :: of_item ( tcx, item. owner_id . to_def_id ( ) ) ;
687
674
}
@@ -691,7 +678,7 @@ pub(super) fn check_specialization_validity<'tcx>(
691
678
trait_def : & ty:: TraitDef ,
692
679
trait_item : & ty:: AssocItem ,
693
680
impl_id : DefId ,
694
- impl_item : & hir :: ImplItemRef ,
681
+ impl_item : DefId ,
695
682
) {
696
683
let Ok ( ancestors) = trait_def. ancestors ( tcx, impl_id) else { return } ;
697
684
let mut ancestor_impls = ancestors. skip ( 1 ) . filter_map ( |parent| {
@@ -737,10 +724,8 @@ pub(super) fn check_specialization_validity<'tcx>(
737
724
738
725
fn check_impl_items_against_trait < ' tcx > (
739
726
tcx : TyCtxt < ' tcx > ,
740
- full_impl_span : Span ,
741
727
impl_id : LocalDefId ,
742
728
impl_trait_ref : ty:: TraitRef < ' tcx > ,
743
- impl_item_refs : & [ hir:: ImplItemRef ] ,
744
729
) {
745
730
// If the trait reference itself is erroneous (so the compilation is going
746
731
// to fail), skip checking the items here -- the `impl_item` table in `tcx`
@@ -749,12 +734,14 @@ fn check_impl_items_against_trait<'tcx>(
749
734
return ;
750
735
}
751
736
737
+ let impl_item_refs = tcx. associated_item_def_ids ( impl_id) ;
738
+
752
739
// Negative impls are not expected to have any items
753
740
match tcx. impl_polarity ( impl_id) {
754
741
ty:: ImplPolarity :: Reservation | ty:: ImplPolarity :: Positive => { }
755
742
ty:: ImplPolarity :: Negative => {
756
743
if let [ first_item_ref, ..] = impl_item_refs {
757
- let first_item_span = tcx. hir ( ) . impl_item ( first_item_ref. id ) . span ;
744
+ let first_item_span = tcx. def_span ( first_item_ref) ;
758
745
struct_span_err ! (
759
746
tcx. sess,
760
747
first_item_span,
@@ -769,43 +756,27 @@ fn check_impl_items_against_trait<'tcx>(
769
756
770
757
let trait_def = tcx. trait_def ( impl_trait_ref. def_id ) ;
771
758
772
- for impl_item in impl_item_refs {
773
- let ty_impl_item = tcx. associated_item ( impl_item. id . owner_id ) ;
759
+ for & impl_item in impl_item_refs {
760
+ let ty_impl_item = tcx. associated_item ( impl_item) ;
774
761
let ty_trait_item = if let Some ( trait_item_id) = ty_impl_item. trait_item_def_id {
775
762
tcx. associated_item ( trait_item_id)
776
763
} else {
777
764
// Checked in `associated_item`.
778
- tcx. sess . delay_span_bug ( impl_item . span , "missing associated item in trait" ) ;
765
+ tcx. sess . delay_span_bug ( tcx . def_span ( impl_item ) , "missing associated item in trait" ) ;
779
766
continue ;
780
767
} ;
781
- let impl_item_full = tcx. hir ( ) . impl_item ( impl_item. id ) ;
782
- match impl_item_full. kind {
783
- hir:: ImplItemKind :: Const ( ..) => {
768
+ match ty_impl_item. kind {
769
+ ty:: AssocKind :: Const => {
784
770
let _ = tcx. compare_impl_const ( (
785
- impl_item. id . owner_id . def_id ,
771
+ impl_item. expect_local ( ) ,
786
772
ty_impl_item. trait_item_def_id . unwrap ( ) ,
787
773
) ) ;
788
774
}
789
- hir:: ImplItemKind :: Fn ( ..) => {
790
- let opt_trait_span = tcx. hir ( ) . span_if_local ( ty_trait_item. def_id ) ;
791
- compare_impl_method (
792
- tcx,
793
- & ty_impl_item,
794
- & ty_trait_item,
795
- impl_trait_ref,
796
- opt_trait_span,
797
- ) ;
775
+ ty:: AssocKind :: Fn => {
776
+ compare_impl_method ( tcx, & ty_impl_item, & ty_trait_item, impl_trait_ref) ;
798
777
}
799
- hir:: ImplItemKind :: Type ( impl_ty) => {
800
- let opt_trait_span = tcx. hir ( ) . span_if_local ( ty_trait_item. def_id ) ;
801
- compare_impl_ty (
802
- tcx,
803
- & ty_impl_item,
804
- impl_ty. span ,
805
- & ty_trait_item,
806
- impl_trait_ref,
807
- opt_trait_span,
808
- ) ;
778
+ ty:: AssocKind :: Type => {
779
+ compare_impl_ty ( tcx, & ty_impl_item, & ty_trait_item, impl_trait_ref) ;
809
780
}
810
781
}
811
782
@@ -840,6 +811,8 @@ fn check_impl_items_against_trait<'tcx>(
840
811
. map_or ( false , |node_item| !node_item. defining_node . is_from_trait ( ) ) ;
841
812
842
813
if !is_implemented_here {
814
+ let full_impl_span =
815
+ tcx. hir ( ) . span_with_body ( tcx. hir ( ) . local_def_id_to_hir_id ( impl_id) ) ;
843
816
match tcx. eval_default_body_stability ( trait_item_id, full_impl_span) {
844
817
EvalResult :: Deny { feature, reason, issue, .. } => default_body_is_unstable (
845
818
tcx,
@@ -866,6 +839,8 @@ fn check_impl_items_against_trait<'tcx>(
866
839
}
867
840
868
841
if !missing_items. is_empty ( ) {
842
+ let full_impl_span =
843
+ tcx. hir ( ) . span_with_body ( tcx. hir ( ) . local_def_id_to_hir_id ( impl_id) ) ;
869
844
missing_items_err ( tcx, tcx. def_span ( impl_id) , & missing_items, full_impl_span) ;
870
845
}
871
846
0 commit comments