Skip to content

Commit d0c6172

Browse files
committed
Better underline for E0057,E0060,E0061
1 parent 46957f0 commit d0c6172

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

src/librustc_typeck/check/mod.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -2432,6 +2432,21 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24322432
let mut expected_arg_tys = expected_arg_tys;
24332433
let expected_arg_count = fn_inputs.len();
24342434

2435+
let sp_args = if args.len() > 0 {
2436+
let (first, args) = args.split_at(1);
2437+
let mut sp_tmp = first[0].span;
2438+
for arg in args {
2439+
let sp_opt = self.sess().codemap().merge_spans(sp_tmp, arg.span);
2440+
if ! sp_opt.is_some() {
2441+
break;
2442+
}
2443+
sp_tmp = sp_opt.unwrap();
2444+
};
2445+
sp_tmp
2446+
} else {
2447+
sp
2448+
};
2449+
24352450
fn parameter_count_error<'tcx>(sess: &Session, sp: Span, fn_inputs: &[Ty<'tcx>],
24362451
expected_count: usize, arg_count: usize, error_code: &str,
24372452
variadic: bool) {
@@ -2464,7 +2479,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24642479
let tuple_type = self.structurally_resolved_type(sp, fn_inputs[0]);
24652480
match tuple_type.sty {
24662481
ty::TyTuple(arg_types) if arg_types.len() != args.len() => {
2467-
parameter_count_error(tcx.sess, sp, fn_inputs, arg_types.len(), args.len(),
2482+
parameter_count_error(tcx.sess, sp_args, fn_inputs, arg_types.len(), args.len(),
24682483
"E0057", false);
24692484
expected_arg_tys = &[];
24702485
self.err_args(args.len())
@@ -2493,14 +2508,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24932508
if supplied_arg_count >= expected_arg_count {
24942509
fn_inputs.to_vec()
24952510
} else {
2496-
parameter_count_error(tcx.sess, sp, fn_inputs, expected_arg_count,
2511+
parameter_count_error(tcx.sess, sp_args, fn_inputs, expected_arg_count,
24972512
supplied_arg_count, "E0060", true);
24982513
expected_arg_tys = &[];
24992514
self.err_args(supplied_arg_count)
25002515
}
25012516
} else {
2502-
parameter_count_error(tcx.sess, sp, fn_inputs, expected_arg_count, supplied_arg_count,
2503-
"E0061", false);
2517+
parameter_count_error(tcx.sess, sp_args, fn_inputs, expected_arg_count,
2518+
supplied_arg_count, "E0061", false);
25042519
expected_arg_tys = &[];
25052520
self.err_args(supplied_arg_count)
25062521
};

src/test/ui/span/E0057.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let f = |x| x * 3;
13+
let a = f(); //~ ERROR E0057
14+
let b = f(4);
15+
let c = f(2, 3); //~ ERROR E0057
16+
}

src/test/ui/span/E0057.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error[E0057]: this function takes 1 parameter but 0 parameters were supplied
2+
--> $DIR/E0057.rs:13:13
3+
|
4+
13 | let a = f(); //~ ERROR E0057
5+
| ^^^
6+
|
7+
= note: the following parameter type was expected: (_,)
8+
9+
error[E0057]: this function takes 1 parameter but 2 parameters were supplied
10+
--> $DIR/E0057.rs:15:15
11+
|
12+
15 | let c = f(2, 3); //~ ERROR E0057
13+
| ^^^^
14+
|
15+
= note: the following parameter type was expected: (_,)
16+
17+
error: aborting due to 2 previous errors
18+

0 commit comments

Comments
 (0)