@@ -2,14 +2,13 @@ use std::cell::LazyCell;
2
2
use std:: ops:: { ControlFlow , Deref } ;
3
3
4
4
use hir:: intravisit:: { self , Visitor } ;
5
- use itertools:: Itertools ;
6
5
use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
7
6
use rustc_errors:: codes:: * ;
8
7
use rustc_errors:: { Applicability , ErrorGuaranteed , pluralize, struct_span_code_err} ;
8
+ use rustc_hir:: ItemKind ;
9
9
use rustc_hir:: def:: { DefKind , Res } ;
10
10
use rustc_hir:: def_id:: { DefId , LocalDefId , LocalModDefId } ;
11
11
use rustc_hir:: lang_items:: LangItem ;
12
- use rustc_hir:: { GenericParamKind , ItemKind } ;
13
12
use rustc_infer:: infer:: outlives:: env:: OutlivesEnvironment ;
14
13
use rustc_infer:: infer:: { self , InferCtxt , TyCtxtInferExt } ;
15
14
use rustc_macros:: LintDiagnostic ;
@@ -378,7 +377,7 @@ fn check_trait_item<'tcx>(
378
377
_ => ( None , trait_item. span ) ,
379
378
} ;
380
379
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) ;
382
381
383
382
if matches ! ( trait_item. kind, hir:: TraitItemKind :: Fn ( ..) ) {
384
383
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>(
387
386
assoc_ty_def_id. expect_local ( ) ,
388
387
tcx. def_span ( assoc_ty_def_id) ,
389
388
None ,
390
- None ,
391
389
) ) ;
392
390
}
393
391
}
@@ -905,13 +903,7 @@ fn check_impl_item<'tcx>(
905
903
hir:: ImplItemKind :: Type ( ty) if ty. span != DUMMY_SP => ( None , ty. span ) ,
906
904
_ => ( None , impl_item. span ) ,
907
905
} ;
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)
915
907
}
916
908
917
909
fn check_param_wf ( tcx : TyCtxt < ' _ > , param : & hir:: GenericParam < ' _ > ) -> Result < ( ) , ErrorGuaranteed > {
@@ -1049,7 +1041,6 @@ fn check_associated_item(
1049
1041
item_id : LocalDefId ,
1050
1042
span : Span ,
1051
1043
sig_if_method : Option < & hir:: FnSig < ' _ > > ,
1052
- generics : Option < & hir:: Generics < ' _ > > ,
1053
1044
) -> Result < ( ) , ErrorGuaranteed > {
1054
1045
let loc = Some ( WellFormedLoc :: Ty ( item_id) ) ;
1055
1046
enter_wf_checking_ctxt ( tcx, span, item_id, |wfcx| {
@@ -1082,7 +1073,7 @@ fn check_associated_item(
1082
1073
hir_sig. decl ,
1083
1074
item. def_id . expect_local ( ) ,
1084
1075
) ;
1085
- check_method_receiver ( wfcx, hir_sig, item, self_ty, generics )
1076
+ check_method_receiver ( wfcx, hir_sig, item, self_ty)
1086
1077
}
1087
1078
ty:: AssocKind :: Type => {
1088
1079
if let ty:: AssocItemContainer :: TraitContainer = item. container {
@@ -1680,10 +1671,11 @@ fn check_method_receiver<'tcx>(
1680
1671
fn_sig : & hir:: FnSig < ' _ > ,
1681
1672
method : ty:: AssocItem ,
1682
1673
self_ty : Ty < ' tcx > ,
1683
- generics : Option < & hir:: Generics < ' _ > > ,
1684
1674
) -> Result < ( ) , ErrorGuaranteed > {
1685
1675
let tcx = wfcx. tcx ( ) ;
1686
1676
1677
+ let generics = tcx. generics_of ( method. def_id ) ;
1678
+
1687
1679
if !method. fn_has_self_parameter {
1688
1680
return Ok ( ( ) ) ;
1689
1681
}
@@ -1801,19 +1793,11 @@ enum ReceiverValidityError {
1801
1793
/// method's type params.
1802
1794
fn confirm_type_is_not_a_method_generic_param (
1803
1795
ty : Ty < ' _ > ,
1804
- method_generics : Option < & hir :: Generics < ' _ > > ,
1796
+ generics : & ty :: Generics ,
1805
1797
) -> Result < ( ) , ReceiverValidityError > {
1806
1798
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 ) ;
1817
1801
}
1818
1802
}
1819
1803
Ok ( ( ) )
@@ -1834,7 +1818,7 @@ fn receiver_is_valid<'tcx>(
1834
1818
receiver_ty : Ty < ' tcx > ,
1835
1819
self_ty : Ty < ' tcx > ,
1836
1820
arbitrary_self_types_enabled : Option < ArbitrarySelfTypesLevel > ,
1837
- generics : Option < & hir :: Generics < ' _ > > ,
1821
+ generics : & ty :: Generics ,
1838
1822
) -> Result < ( ) , ReceiverValidityError > {
1839
1823
let infcx = wfcx. infcx ;
1840
1824
let tcx = wfcx. tcx ( ) ;
0 commit comments