From d0c6172501e03e4021345f86a2123ca2e88eaf46 Mon Sep 17 00:00:00 2001 From: Andrea Corradi Date: Thu, 1 Sep 2016 10:34:30 +0200 Subject: [PATCH] Better underline for E0057,E0060,E0061 --- src/librustc_typeck/check/mod.rs | 23 +++++++++++++++++++---- src/test/ui/span/E0057.rs | 16 ++++++++++++++++ src/test/ui/span/E0057.stderr | 18 ++++++++++++++++++ 3 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/test/ui/span/E0057.rs create mode 100644 src/test/ui/span/E0057.stderr diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 79c1c5fb5e2..155a858c1bb 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -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) { @@ -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()) @@ -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) }; diff --git a/src/test/ui/span/E0057.rs b/src/test/ui/span/E0057.rs new file mode 100644 index 00000000000..1fb5498b099 --- /dev/null +++ b/src/test/ui/span/E0057.rs @@ -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 or the MIT license +// , 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 +} diff --git a/src/test/ui/span/E0057.stderr b/src/test/ui/span/E0057.stderr new file mode 100644 index 00000000000..656fdbe2b29 --- /dev/null +++ b/src/test/ui/span/E0057.stderr @@ -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 +