From 90bf7cdd79f3efb8695909240ff927024c42fce4 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Thu, 16 Oct 2014 19:03:29 -0700 Subject: [PATCH 1/2] Fix ICE in overloaded call with incorrect arity When an overloaded call expression has parameters but the function object takes none, construct an array of formal argument types with the arity of the call expression so that we don't fail by indexing out of bounds later. Closes #16939 --- src/librustc/middle/typeck/check/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index be622bd6855..06f4a48189f 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -2516,8 +2516,10 @@ fn check_argument_types<'a>(fcx: &FnCtxt, "this function takes 0 parameters but {} parameter{} supplied", args.len(), if args.len() == 1 {" was"} else {"s were"}); + err_args(args.len()) + } else { + vec![] } - Vec::new() } _ => { span_err!(tcx.sess, sp, E0059, From 0e68c63f3f148309bcc5c5f1358af49db393c619 Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Thu, 16 Oct 2014 19:08:42 -0700 Subject: [PATCH 2/2] Add regression test for issue #16939 --- src/test/compile-fail/issue-16939.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/test/compile-fail/issue-16939.rs diff --git a/src/test/compile-fail/issue-16939.rs b/src/test/compile-fail/issue-16939.rs new file mode 100644 index 00000000000..8e7a2a9db3d --- /dev/null +++ b/src/test/compile-fail/issue-16939.rs @@ -0,0 +1,20 @@ +// Copyright 2014 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(overloaded_calls)] + +// Make sure we don't ICE when making an overloaded call with the +// wrong arity. + +fn _foo (f: F) { + |t| f(t); //~ ERROR E0058 +} + +fn main() {}