Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let mut expected_arg_tys = expected_arg_tys;
let expected_arg_count = fn_inputs.len();

let sp_args = if args.len() > 0 {
let (first, args) = args.split_at(1);
let mut sp_tmp = first[0].span;
for arg in args {
let sp_opt = self.sess().codemap().merge_spans(sp_tmp, arg.span);
if ! sp_opt.is_some() {
break;
}
sp_tmp = sp_opt.unwrap();
};
sp_tmp
} else {
sp
};

fn parameter_count_error<'tcx>(sess: &Session, sp: Span, fn_inputs: &[Ty<'tcx>],
expected_count: usize, arg_count: usize, error_code: &str,
variadic: bool) {
Expand Down Expand Up @@ -2464,7 +2479,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
let tuple_type = self.structurally_resolved_type(sp, fn_inputs[0]);
match tuple_type.sty {
ty::TyTuple(arg_types) if arg_types.len() != args.len() => {
parameter_count_error(tcx.sess, sp, fn_inputs, arg_types.len(), args.len(),
parameter_count_error(tcx.sess, sp_args, fn_inputs, arg_types.len(), args.len(),
"E0057", false);
expected_arg_tys = &[];
self.err_args(args.len())
Expand Down Expand Up @@ -2493,14 +2508,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if supplied_arg_count >= expected_arg_count {
fn_inputs.to_vec()
} else {
parameter_count_error(tcx.sess, sp, fn_inputs, expected_arg_count,
parameter_count_error(tcx.sess, sp_args, fn_inputs, expected_arg_count,
supplied_arg_count, "E0060", true);
expected_arg_tys = &[];
self.err_args(supplied_arg_count)
}
} else {
parameter_count_error(tcx.sess, sp, fn_inputs, expected_arg_count, supplied_arg_count,
"E0061", false);
parameter_count_error(tcx.sess, sp_args, fn_inputs, expected_arg_count,
supplied_arg_count, "E0061", false);
expected_arg_tys = &[];
self.err_args(supplied_arg_count)
};
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/span/E0057.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2016 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

fn main() {
let f = |x| x * 3;
let a = f(); //~ ERROR E0057
let b = f(4);
let c = f(2, 3); //~ ERROR E0057
}
18 changes: 18 additions & 0 deletions src/test/ui/span/E0057.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error[E0057]: this function takes 1 parameter but 0 parameters were supplied
--> $DIR/E0057.rs:13:13
|
13 | let a = f(); //~ ERROR E0057
| ^^^
|
= note: the following parameter type was expected: (_,)

error[E0057]: this function takes 1 parameter but 2 parameters were supplied
--> $DIR/E0057.rs:15:15
|
15 | let c = f(2, 3); //~ ERROR E0057
| ^^^^
|
= note: the following parameter type was expected: (_,)

error: aborting due to 2 previous errors