about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2016-10-07 11:45:04 +0200
committerGitHub <noreply@github.com>2016-10-07 11:45:04 +0200
commit85e95cc801d982c8c603dc02dd544895401ac8bf (patch)
tree5dd50c84104e7fc6b24ca38b9f5ff90f63d6a220
parentb4e89728f450aba54efb9fa88e95a84acaae862b (diff)
parentd0c6172501e03e4021345f86a2123ca2e88eaf46 (diff)
downloadrust-85e95cc801d982c8c603dc02dd544895401ac8bf.tar.gz
rust-85e95cc801d982c8c603dc02dd544895401ac8bf.zip
Rollup merge of #36222 - acrrd:better_underline_E0057, r=GuillaumeGomez
Better underline for E0057,E0060,E0061

Fix #35214
Part of #35233

r? @jonathandturner
-rw-r--r--src/librustc_typeck/check/mod.rs23
-rw-r--r--src/test/ui/span/E0057.rs16
-rw-r--r--src/test/ui/span/E0057.stderr18
3 files changed, 53 insertions, 4 deletions
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 <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
+}
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
+