@@ -2373,9 +2373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23732373 let mut generics_with_unmatched_params = Vec :: new ( ) ;
23742374
23752375 let check_for_matched_generics = || {
2376- if matched_inputs. iter ( ) . any ( |x| x. is_some ( ) )
2377- && params_with_generics. iter ( ) . any ( |( x, _) | x. is_some ( ) )
2378- {
2376+ if matched_inputs. iter ( ) . any ( |x| x. is_some ( ) ) {
23792377 for ( idx, ( generic, _) ) in params_with_generics. iter_enumerated ( ) {
23802378 // Param has to have a generic and be matched to be relevant
23812379 if matched_inputs[ idx] . is_none ( ) {
@@ -2666,8 +2664,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26662664 }
26672665
26682666 /// Returns the parameters of a function, with their generic parameters if those are the full
2669- /// type of that parameter. Returns `None` if the function has no generics or the body is
2670- /// unavailable (eg is an instrinsic).
2667+ /// type of that parameter.
2668+ ///
2669+ /// Returns `None` if the function has no parameters taking generic type, or the function is
2670+ /// both not a trait function and has no available body (eg is an instrinsic).
26712671 fn get_hir_params_with_generics (
26722672 & self ,
26732673 def_id : DefId ,
@@ -2695,33 +2695,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26952695 } ;
26962696
26972697 // Make sure to remove both the receiver and variadic argument. Both are removed
2698- // when matching parameter types.
2698+ // when warning about mismatched parameters.
2699+ let mut found_generic = false ;
26992700 let fn_inputs = sig. decl . inputs . get ( is_method as usize ..) ?. iter ( ) . map ( |param| {
27002701 if let hir:: TyKind :: Path ( QPath :: Resolved (
27012702 _,
27022703 & hir:: Path { res : Res :: Def ( _, res_def_id) , .. } ,
27032704 ) ) = param. kind
27042705 {
2705- generics. params . iter ( ) . find ( |param| param. def_id . to_def_id ( ) == res_def_id)
2706+ let res =
2707+ generics. params . iter ( ) . find ( |param| param. def_id . to_def_id ( ) == res_def_id) ;
2708+ found_generic |= res. is_some ( ) ;
2709+ res
27062710 } else {
27072711 None
27082712 }
27092713 } ) ;
2710- match ( body_id, param_names) {
2714+ let res = match ( body_id, param_names) {
27112715 ( Some ( _) , Some ( _) ) | ( None , None ) => unreachable ! ( ) ,
27122716 ( Some ( body) , None ) => {
27132717 let params = self . tcx . hir ( ) . body ( body) . params ;
27142718 let params =
27152719 params. get ( is_method as usize ..params. len ( ) - sig. decl . c_variadic as usize ) ?;
27162720 debug_assert_eq ! ( params. len( ) , fn_inputs. len( ) ) ;
2717- Some ( fn_inputs. zip ( params. iter ( ) . map ( |param| FnParam :: Param ( param) ) ) . collect ( ) )
2721+ fn_inputs. zip ( params. iter ( ) . map ( |param| FnParam :: Param ( param) ) ) . collect ( )
27182722 }
27192723 ( None , Some ( params) ) => {
27202724 let params = params. get ( is_method as usize ..) ?;
27212725 debug_assert_eq ! ( params. len( ) , fn_inputs. len( ) ) ;
2722- Some ( fn_inputs. zip ( params. iter ( ) . map ( |param| FnParam :: Name ( param) ) ) . collect ( ) )
2726+ fn_inputs. zip ( params. iter ( ) . map ( |param| FnParam :: Name ( param) ) ) . collect ( )
27232727 }
2724- }
2728+ } ;
2729+ found_generic. then_some ( res)
27252730 }
27262731}
27272732
0 commit comments