@@ -2373,9 +2373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2373
2373
let mut generics_with_unmatched_params = Vec :: new ( ) ;
2374
2374
2375
2375
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 ( ) ) {
2379
2377
for ( idx, ( generic, _) ) in params_with_generics. iter_enumerated ( ) {
2380
2378
// Param has to have a generic and be matched to be relevant
2381
2379
if matched_inputs[ idx] . is_none ( ) {
@@ -2666,8 +2664,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2666
2664
}
2667
2665
2668
2666
/// 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).
2671
2671
fn get_hir_params_with_generics (
2672
2672
& self ,
2673
2673
def_id : DefId ,
@@ -2695,33 +2695,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
2695
2695
} ;
2696
2696
2697
2697
// 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 ;
2699
2700
let fn_inputs = sig. decl . inputs . get ( is_method as usize ..) ?. iter ( ) . map ( |param| {
2700
2701
if let hir:: TyKind :: Path ( QPath :: Resolved (
2701
2702
_,
2702
2703
& hir:: Path { res : Res :: Def ( _, res_def_id) , .. } ,
2703
2704
) ) = param. kind
2704
2705
{
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
2706
2710
} else {
2707
2711
None
2708
2712
}
2709
2713
} ) ;
2710
- match ( body_id, param_names) {
2714
+ let res = match ( body_id, param_names) {
2711
2715
( Some ( _) , Some ( _) ) | ( None , None ) => unreachable ! ( ) ,
2712
2716
( Some ( body) , None ) => {
2713
2717
let params = self . tcx . hir ( ) . body ( body) . params ;
2714
2718
let params =
2715
2719
params. get ( is_method as usize ..params. len ( ) - sig. decl . c_variadic as usize ) ?;
2716
2720
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 ( )
2718
2722
}
2719
2723
( None , Some ( params) ) => {
2720
2724
let params = params. get ( is_method as usize ..) ?;
2721
2725
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 ( )
2723
2727
}
2724
- }
2728
+ } ;
2729
+ found_generic. then_some ( || res)
2725
2730
}
2726
2731
}
2727
2732
0 commit comments