@@ -298,6 +298,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
298298 // call's arguments and we can provide a more explicit span.
299299 let sig = self . tcx . fn_sig ( def_id) . subst_identity ( ) ;
300300 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+ }
301307 let rcvr_ty = self . node_ty ( rcvr. hir_id ) ;
302308 // Get the evaluated type *after* calling the method call, so that the influence
303309 // of the arguments can be reflected in the receiver type. The receiver
@@ -323,13 +329,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
323329 let mut param_found = FxHashMap :: default ( ) ;
324330 if self . can_eq ( self . param_env , ty, found) {
325331 // 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 ) {
327333 if def_self_ty. contains ( * param_ty) && let ty:: Param ( _) = param_ty. kind ( ) {
328334 // We found an argument that references a type parameter in `Self`,
329335 // so we assume that this is the argument that caused the found
330336 // type, which we know already because of `can_eq` above was first
331337 // inferred in this method call.
332- let arg = & args[ i] ;
333338 let arg_ty = self . node_ty ( arg. hir_id ) ;
334339 if !arg. span . overlaps ( mismatch_span) {
335340 err. span_label (
0 commit comments