@@ -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 ;
@@ -379,7 +378,7 @@ fn check_trait_item<'tcx>(
379378 _ => ( None , trait_item. span ) ,
380379 } ;
381380 check_dyn_incompatible_self_trait_by_name ( tcx, trait_item) ;
382- let mut res = check_associated_item ( tcx, def_id, span, method_sig, None ) ;
381+ let mut res = check_associated_item ( tcx, def_id, span, method_sig) ;
383382
384383 if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) ) {
385384 for & assoc_ty_def_id in tcx. associated_types_for_impl_traits_in_associated_fn ( def_id) {
@@ -388,7 +387,6 @@ fn check_trait_item<'tcx>(
388387 assoc_ty_def_id. expect_local ( ) ,
389388 tcx. def_span ( assoc_ty_def_id) ,
390389 None ,
391- None ,
392390 ) ) ;
393391 }
394392 }
@@ -906,13 +904,7 @@ fn check_impl_item<'tcx>(
906904 hir:: ImplItemKind :: Type ( ty) if ty. span != DUMMY_SP => ( None , ty. span ) ,
907905 _ => ( None , impl_item. span ) ,
908906 } ;
909- check_associated_item (
910- tcx,
911- impl_item. owner_id . def_id ,
912- span,
913- method_sig,
914- Some ( impl_item. generics ) ,
915- )
907+ check_associated_item ( tcx, impl_item. owner_id . def_id , span, method_sig)
916908}
917909
918910fn check_param_wf ( tcx : TyCtxt < ' _ > , param : & hir:: GenericParam < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
@@ -1045,7 +1037,6 @@ fn check_associated_item(
10451037 item_id : LocalDefId ,
10461038 span : Span ,
10471039 sig_if_method : Option < & hir:: FnSig < ' _ > > ,
1048- generics : Option < & hir:: Generics < ' _ > > ,
10491040) -> Result < ( ) , ErrorGuaranteed > {
10501041 let loc = Some ( WellFormedLoc :: Ty ( item_id) ) ;
10511042 enter_wf_checking_ctxt ( tcx, span, item_id, |wfcx| {
@@ -1078,7 +1069,7 @@ fn check_associated_item(
10781069 hir_sig. decl ,
10791070 item. def_id . expect_local ( ) ,
10801071 ) ;
1081- check_method_receiver ( wfcx, hir_sig, item, self_ty, generics )
1072+ check_method_receiver ( wfcx, hir_sig, item, self_ty)
10821073 }
10831074 ty:: AssocKind :: Type => {
10841075 if let ty:: AssocItemContainer :: TraitContainer = item. container {
@@ -1700,7 +1691,6 @@ fn check_method_receiver<'tcx>(
17001691 fn_sig : & hir:: FnSig < ' _ > ,
17011692 method : ty:: AssocItem ,
17021693 self_ty : Ty < ' tcx > ,
1703- generics : Option < & hir:: Generics < ' _ > > ,
17041694) -> Result < ( ) , ErrorGuaranteed > {
17051695 let tcx = wfcx. tcx ( ) ;
17061696
@@ -1734,6 +1724,7 @@ fn check_method_receiver<'tcx>(
17341724 } else {
17351725 None
17361726 } ;
1727+ let generics = tcx. generics_of ( method. def_id ) ;
17371728
17381729 let receiver_validity =
17391730 receiver_is_valid ( wfcx, span, receiver_ty, self_ty, arbitrary_self_types_level, generics) ;
@@ -1821,19 +1812,11 @@ enum ReceiverValidityError {
18211812/// method's type params.
18221813fn confirm_type_is_not_a_method_generic_param (
18231814 ty : Ty < ' _ > ,
1824- method_generics : Option < & hir :: Generics < ' _ > > ,
1815+ method_generics : & ty :: Generics ,
18251816) -> Result < ( ) , ReceiverValidityError > {
18261817 if let ty:: Param ( param) = ty. kind ( ) {
1827- if let Some ( generics) = method_generics {
1828- if generics
1829- . params
1830- . iter ( )
1831- . filter ( |g| matches ! ( g. kind, GenericParamKind :: Type { .. } ) )
1832- . map ( |g| g. name . ident ( ) . name )
1833- . contains ( & param. name )
1834- {
1835- return Err ( ReceiverValidityError :: MethodGenericParamUsed ) ;
1836- }
1818+ if ( param. index as usize ) >= method_generics. parent_count {
1819+ return Err ( ReceiverValidityError :: MethodGenericParamUsed ) ;
18371820 }
18381821 }
18391822 Ok ( ( ) )
@@ -1854,7 +1837,7 @@ fn receiver_is_valid<'tcx>(
18541837 receiver_ty : Ty < ' tcx > ,
18551838 self_ty : Ty < ' tcx > ,
18561839 arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1857- generics : Option < & hir :: Generics < ' _ > > ,
1840+ method_generics : & ty :: Generics ,
18581841) -> Result < ( ) , ReceiverValidityError > {
18591842 let infcx = wfcx. infcx ;
18601843 let tcx = wfcx. tcx ( ) ;
@@ -1870,7 +1853,7 @@ fn receiver_is_valid<'tcx>(
18701853 return Ok ( ( ) ) ;
18711854 }
18721855
1873- confirm_type_is_not_a_method_generic_param ( receiver_ty, generics ) ?;
1856+ confirm_type_is_not_a_method_generic_param ( receiver_ty, method_generics ) ?;
18741857
18751858 let mut autoderef = Autoderef :: new ( infcx, wfcx. param_env , wfcx. body_def_id , span, receiver_ty) ;
18761859
@@ -1888,7 +1871,7 @@ fn receiver_is_valid<'tcx>(
18881871 potential_self_ty, self_ty
18891872 ) ;
18901873
1891- confirm_type_is_not_a_method_generic_param ( potential_self_ty, generics ) ?;
1874+ confirm_type_is_not_a_method_generic_param ( potential_self_ty, method_generics ) ?;
18921875
18931876 // Check if the self type unifies. If it does, then commit the result
18941877 // since it may have region side-effects.
0 commit comments