@@ -298,6 +298,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
298
298
// call's arguments and we can provide a more explicit span.
299
299
let sig = self . tcx . fn_sig ( def_id) . subst_identity ( ) ;
300
300
let def_self_ty = sig. input ( 0 ) . skip_binder ( ) ;
301
+ let param_tys = sig. inputs ( ) . skip_binder ( ) . iter ( ) . skip ( 1 ) ;
302
+ // If there's an arity mismatch, pointing out the call as the source of an inference
303
+ // can be misleading, so we skip it.
304
+ if param_tys. len ( ) != args. len ( ) {
305
+ continue ;
306
+ }
301
307
let rcvr_ty = self . node_ty ( rcvr. hir_id ) ;
302
308
// Get the evaluated type *after* calling the method call, so that the influence
303
309
// of the arguments can be reflected in the receiver type. The receiver
@@ -323,13 +329,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
323
329
let mut param_found = FxHashMap :: default ( ) ;
324
330
if self . can_eq ( self . param_env , ty, found) {
325
331
// We only point at the first place where the found type was inferred.
326
- for ( i , param_ty ) in sig . inputs ( ) . skip_binder ( ) . iter ( ) . skip ( 1 ) . enumerate ( ) {
332
+ for ( param_ty , arg ) in param_tys . zip ( args ) {
327
333
if def_self_ty. contains ( * param_ty) && let ty:: Param ( _) = param_ty. kind ( ) {
328
334
// We found an argument that references a type parameter in `Self`,
329
335
// so we assume that this is the argument that caused the found
330
336
// type, which we know already because of `can_eq` above was first
331
337
// inferred in this method call.
332
- let arg = & args[ i] ;
333
338
let arg_ty = self . node_ty ( arg. hir_id ) ;
334
339
if !arg. span . overlaps ( mismatch_span) {
335
340
err. span_label (
0 commit comments