@@ -2,14 +2,13 @@ use std::cell::LazyCell;
22use std:: ops:: { ControlFlow , Deref } ;
33
44use hir:: intravisit:: { self , Visitor } ;
5- use itertools:: Itertools ;
65use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
76use rustc_errors:: codes:: * ;
87use rustc_errors:: { Applicability , ErrorGuaranteed , pluralize, struct_span_code_err} ;
8+ use rustc_hir:: ItemKind ;
99use rustc_hir:: def:: { DefKind , Res } ;
1010use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
1111use rustc_hir:: lang_items:: LangItem ;
12- use rustc_hir:: { GenericParamKind , ItemKind } ;
1312use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
1413use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
1514use rustc_macros:: LintDiagnostic ;
@@ -378,7 +377,7 @@ fn check_trait_item<'tcx>(
378377 _ => ( None , trait_item. span ) ,
379378 } ;
380379 check_dyn_incompatible_self_trait_by_name ( tcx, trait_item) ;
381- let mut res = check_associated_item ( tcx, def_id, span, method_sig, None ) ;
380+ let mut res = check_associated_item ( tcx, def_id, span, method_sig) ;
382381
383382 if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) ) {
384383 for & assoc_ty_def_id in tcx. associated_types_for_impl_traits_in_associated_fn ( def_id) {
@@ -387,7 +386,6 @@ fn check_trait_item<'tcx>(
387386 assoc_ty_def_id. expect_local ( ) ,
388387 tcx. def_span ( assoc_ty_def_id) ,
389388 None ,
390- None ,
391389 ) ) ;
392390 }
393391 }
@@ -905,13 +903,7 @@ fn check_impl_item<'tcx>(
905903 hir:: ImplItemKind :: Type ( ty) if ty. span != DUMMY_SP => ( None , ty. span ) ,
906904 _ => ( None , impl_item. span ) ,
907905 } ;
908- check_associated_item (
909- tcx,
910- impl_item. owner_id . def_id ,
911- span,
912- method_sig,
913- Some ( impl_item. generics ) ,
914- )
906+ check_associated_item ( tcx, impl_item. owner_id . def_id , span, method_sig)
915907}
916908
917909fn check_param_wf ( tcx : TyCtxt < ' _ > , param : & hir:: GenericParam < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
@@ -1049,7 +1041,6 @@ fn check_associated_item(
10491041 item_id : LocalDefId ,
10501042 span : Span ,
10511043 sig_if_method : Option < & hir:: FnSig < ' _ > > ,
1052- generics : Option < & hir:: Generics < ' _ > > ,
10531044) -> Result < ( ) , ErrorGuaranteed > {
10541045 let loc = Some ( WellFormedLoc :: Ty ( item_id) ) ;
10551046 enter_wf_checking_ctxt ( tcx, span, item_id, |wfcx| {
@@ -1082,7 +1073,7 @@ fn check_associated_item(
10821073 hir_sig. decl ,
10831074 item. def_id . expect_local ( ) ,
10841075 ) ;
1085- check_method_receiver ( wfcx, hir_sig, item, self_ty, generics )
1076+ check_method_receiver ( wfcx, hir_sig, item, self_ty)
10861077 }
10871078 ty:: AssocKind :: Type => {
10881079 if let ty:: AssocItemContainer :: TraitContainer = item. container {
@@ -1680,10 +1671,11 @@ fn check_method_receiver<'tcx>(
16801671 fn_sig : & hir:: FnSig < ' _ > ,
16811672 method : ty:: AssocItem ,
16821673 self_ty : Ty < ' tcx > ,
1683- generics : Option < & hir:: Generics < ' _ > > ,
16841674) -> Result < ( ) , ErrorGuaranteed > {
16851675 let tcx = wfcx. tcx ( ) ;
16861676
1677+ let generics = tcx. generics_of ( method. def_id ) ;
1678+
16871679 if !method. fn_has_self_parameter {
16881680 return Ok ( ( ) ) ;
16891681 }
@@ -1801,19 +1793,11 @@ enum ReceiverValidityError {
18011793/// method's type params.
18021794fn confirm_type_is_not_a_method_generic_param (
18031795 ty : Ty < ' _ > ,
1804- method_generics : Option < & hir :: Generics < ' _ > > ,
1796+ generics : & ty :: Generics ,
18051797) -> Result < ( ) , ReceiverValidityError > {
18061798 if let ty:: Param ( param) = ty. kind ( ) {
1807- if let Some ( generics) = method_generics {
1808- if generics
1809- . params
1810- . iter ( )
1811- . filter ( |g| matches ! ( g. kind, GenericParamKind :: Type { .. } ) )
1812- . map ( |g| g. name . ident ( ) . name )
1813- . contains ( & param. name )
1814- {
1815- return Err ( ReceiverValidityError :: MethodGenericParamUsed ) ;
1816- }
1799+ if ( param. index as usize ) >= generics. parent_count {
1800+ return Err ( ReceiverValidityError :: MethodGenericParamUsed ) ;
18171801 }
18181802 }
18191803 Ok ( ( ) )
@@ -1834,7 +1818,7 @@ fn receiver_is_valid<'tcx>(
18341818 receiver_ty : Ty < ' tcx > ,
18351819 self_ty : Ty < ' tcx > ,
18361820 arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1837- generics : Option < & hir :: Generics < ' _ > > ,
1821+ generics : & ty :: Generics ,
18381822) -> Result < ( ) , ReceiverValidityError > {
18391823 let infcx = wfcx. infcx ;
18401824 let tcx = wfcx. tcx ( ) ;
0 commit comments