From 61318156f86c828b7d09decf45ea8e40aafbcc25 Mon Sep 17 00:00:00 2001 From: William Lee Date: Thu, 4 Aug 2016 00:32:49 -0400 Subject: [PATCH 1/3] Fixes for issues #35215 and #35216 --- src/librustc_typeck/check/mod.rs | 6 ++++++ src/test/compile-fail/E0060.rs | 2 ++ src/test/compile-fail/E0061.rs | 4 +++- src/test/compile-fail/issue-18819.rs | 1 + src/test/compile-fail/issue-3044.rs | 2 +- src/test/compile-fail/issue-4935.rs | 1 + src/test/compile-fail/method-call-err-msg.rs | 3 +++ src/test/compile-fail/not-enough-arguments.rs | 1 + src/test/compile-fail/overloaded-calls-bad.rs | 2 ++ src/test/compile-fail/variadic-ffi-3.rs | 2 ++ 10 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 6062bd048b3d2..de81ae26f5dd5 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2384,6 +2384,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { arg_count, if arg_count == 1 {" was"} else {"s were"}), error_code); + + err.span_label(sp, &format!("expected {}{} parameter{}", + if variadic {"at least "} else {""}, + expected_count, + if expected_count == 1 {""} else {"s"})); + let input_types = fn_inputs.iter().map(|i| format!("{:?}", i)).collect::>(); if input_types.len() > 0 { err.note(&format!("the following parameter type{} expected: {}", diff --git a/src/test/compile-fail/E0060.rs b/src/test/compile-fail/E0060.rs index b4a2898749792..f0aecba8afe5e 100644 --- a/src/test/compile-fail/E0060.rs +++ b/src/test/compile-fail/E0060.rs @@ -14,4 +14,6 @@ extern "C" { fn main() { unsafe { printf(); } //~ ERROR E0060 + //~| NOTE expected at least 1 parameter + //~| NOTE the following parameter type was expected } diff --git a/src/test/compile-fail/E0061.rs b/src/test/compile-fail/E0061.rs index 4a8eac2a9e226..3d8622647ef2f 100644 --- a/src/test/compile-fail/E0061.rs +++ b/src/test/compile-fail/E0061.rs @@ -11,5 +11,7 @@ fn f(a: u16, b: &str) {} fn main() { - f(0); //~ ERROR E0061 + f(0); //~ ERROR E0061 + //~| NOTE expected 2 parameters + //~| NOTE the following parameter types were expected } diff --git a/src/test/compile-fail/issue-18819.rs b/src/test/compile-fail/issue-18819.rs index 3591b9824145b..b6bdd4c2e65dd 100644 --- a/src/test/compile-fail/issue-18819.rs +++ b/src/test/compile-fail/issue-18819.rs @@ -25,4 +25,5 @@ fn print_x(_: &Foo, extra: &str) { fn main() { print_x(X); //~error this function takes 2 parameters but 1 parameter was supplied //~^ NOTE the following parameter types were expected: &Foo, &str + //~| NOTE expected 2 parameters } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 68046056fb315..144ceafdbfcd7 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -15,6 +15,6 @@ fn main() { }); //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied //~^^^ NOTE the following parameter types were expected - // + //~| NOTE expected 2 parameters // the first error is, um, non-ideal. } diff --git a/src/test/compile-fail/issue-4935.rs b/src/test/compile-fail/issue-4935.rs index 438d238b6fe62..9ca4de7878ce5 100644 --- a/src/test/compile-fail/issue-4935.rs +++ b/src/test/compile-fail/issue-4935.rs @@ -13,3 +13,4 @@ fn foo(a: usize) {} fn main() { foo(5, 6) } //~ ERROR this function takes 1 parameter but 2 parameters were supplied //~^ NOTE the following parameter type was expected +//~| NOTE expected 1 parameter diff --git a/src/test/compile-fail/method-call-err-msg.rs b/src/test/compile-fail/method-call-err-msg.rs index 212c09364cf4c..bcf676dbede6f 100644 --- a/src/test/compile-fail/method-call-err-msg.rs +++ b/src/test/compile-fail/method-call-err-msg.rs @@ -20,10 +20,13 @@ impl Foo { fn main() { let x = Foo; x.zero(0) //~ ERROR this function takes 0 parameters but 1 parameter was supplied + //~^ NOTE expected 0 parameters .one() //~ ERROR this function takes 1 parameter but 0 parameters were supplied //~^ NOTE the following parameter type was expected + //~| NOTE expected 1 parameter .two(0); //~ ERROR this function takes 2 parameters but 1 parameter was supplied //~^ NOTE the following parameter types were expected + //~| NOTE expected 2 parameters let y = Foo; y.zero() diff --git a/src/test/compile-fail/not-enough-arguments.rs b/src/test/compile-fail/not-enough-arguments.rs index 1f5a54477dd6d..8dcde2cf48ce2 100644 --- a/src/test/compile-fail/not-enough-arguments.rs +++ b/src/test/compile-fail/not-enough-arguments.rs @@ -20,4 +20,5 @@ fn main() { foo(1, 2, 3); //~^ ERROR this function takes 4 parameters but 3 //~^^ NOTE the following parameter types were expected + //~| NOTE expected 4 parameters } diff --git a/src/test/compile-fail/overloaded-calls-bad.rs b/src/test/compile-fail/overloaded-calls-bad.rs index 8763fb0913a87..5865d93e1282f 100644 --- a/src/test/compile-fail/overloaded-calls-bad.rs +++ b/src/test/compile-fail/overloaded-calls-bad.rs @@ -42,7 +42,9 @@ fn main() { let ans = s(); //~^ ERROR this function takes 1 parameter but 0 parameters were supplied //~| NOTE the following parameter type was expected + //~| NOTE expected 1 parameter let ans = s("burma", "shave"); //~^ ERROR this function takes 1 parameter but 2 parameters were supplied //~| NOTE the following parameter type was expected + //~| NOTE expected 1 parameter } diff --git a/src/test/compile-fail/variadic-ffi-3.rs b/src/test/compile-fail/variadic-ffi-3.rs index d8620ead83639..cc9a7c84eded4 100644 --- a/src/test/compile-fail/variadic-ffi-3.rs +++ b/src/test/compile-fail/variadic-ffi-3.rs @@ -18,8 +18,10 @@ fn main() { unsafe { foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied //~^ NOTE the following parameter types were expected + //~| NOTE expected at least 2 parameters foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied //~^ NOTE the following parameter types were expected + //~| NOTE expected at least 2 parameters let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~^ ERROR: mismatched types From 0e756840f0625f06a5e150528820e96316f7929f Mon Sep 17 00:00:00 2001 From: William Lee Date: Thu, 4 Aug 2016 08:07:14 -0400 Subject: [PATCH 2/3] Tidying up some of the line spacing / code formatting for NOTE/ERROR annotation to match other files. --- src/test/compile-fail/E0060.rs | 7 ++++--- src/test/compile-fail/E0061.rs | 7 ++++--- src/test/compile-fail/issue-18819.rs | 5 +++-- src/test/compile-fail/issue-3044.rs | 2 +- src/test/compile-fail/issue-4935.rs | 5 +++-- src/test/compile-fail/not-enough-arguments.rs | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/test/compile-fail/E0060.rs b/src/test/compile-fail/E0060.rs index f0aecba8afe5e..342ad3f2148ae 100644 --- a/src/test/compile-fail/E0060.rs +++ b/src/test/compile-fail/E0060.rs @@ -13,7 +13,8 @@ extern "C" { } fn main() { - unsafe { printf(); } //~ ERROR E0060 - //~| NOTE expected at least 1 parameter - //~| NOTE the following parameter type was expected + unsafe { printf(); } + //~^ ERROR E0060 + //~| NOTE expected at least 1 parameter + //~| NOTE the following parameter type was expected } diff --git a/src/test/compile-fail/E0061.rs b/src/test/compile-fail/E0061.rs index 3d8622647ef2f..83b32200019f5 100644 --- a/src/test/compile-fail/E0061.rs +++ b/src/test/compile-fail/E0061.rs @@ -11,7 +11,8 @@ fn f(a: u16, b: &str) {} fn main() { - f(0); //~ ERROR E0061 - //~| NOTE expected 2 parameters - //~| NOTE the following parameter types were expected + f(0); + //~^ ERROR E0061 + //~| NOTE expected 2 parameters + //~| NOTE the following parameter types were expected } diff --git a/src/test/compile-fail/issue-18819.rs b/src/test/compile-fail/issue-18819.rs index b6bdd4c2e65dd..0310b4ea75fe1 100644 --- a/src/test/compile-fail/issue-18819.rs +++ b/src/test/compile-fail/issue-18819.rs @@ -23,7 +23,8 @@ fn print_x(_: &Foo, extra: &str) { } fn main() { - print_x(X); //~error this function takes 2 parameters but 1 parameter was supplied - //~^ NOTE the following parameter types were expected: &Foo, &str + print_x(X); + //~^ ERROR this function takes 2 parameters but 1 parameter was supplied + //~| NOTE the following parameter types were expected: &Foo, &str //~| NOTE expected 2 parameters } diff --git a/src/test/compile-fail/issue-3044.rs b/src/test/compile-fail/issue-3044.rs index 144ceafdbfcd7..d19e3b2c7b0a8 100644 --- a/src/test/compile-fail/issue-3044.rs +++ b/src/test/compile-fail/issue-3044.rs @@ -14,7 +14,7 @@ fn main() { needlesArr.iter().fold(|x, y| { }); //~^^ ERROR this function takes 2 parameters but 1 parameter was supplied - //~^^^ NOTE the following parameter types were expected + //~| NOTE the following parameter types were expected //~| NOTE expected 2 parameters // the first error is, um, non-ideal. } diff --git a/src/test/compile-fail/issue-4935.rs b/src/test/compile-fail/issue-4935.rs index 9ca4de7878ce5..58a84f3490b3c 100644 --- a/src/test/compile-fail/issue-4935.rs +++ b/src/test/compile-fail/issue-4935.rs @@ -11,6 +11,7 @@ // Regression test for issue #4935 fn foo(a: usize) {} -fn main() { foo(5, 6) } //~ ERROR this function takes 1 parameter but 2 parameters were supplied -//~^ NOTE the following parameter type was expected +fn main() { foo(5, 6) } +//~^ ERROR this function takes 1 parameter but 2 parameters were supplied +//~| NOTE the following parameter type was expected //~| NOTE expected 1 parameter diff --git a/src/test/compile-fail/not-enough-arguments.rs b/src/test/compile-fail/not-enough-arguments.rs index 8dcde2cf48ce2..f2f61fcaeec16 100644 --- a/src/test/compile-fail/not-enough-arguments.rs +++ b/src/test/compile-fail/not-enough-arguments.rs @@ -19,6 +19,6 @@ fn foo(a: isize, b: isize, c: isize, d:isize) { fn main() { foo(1, 2, 3); //~^ ERROR this function takes 4 parameters but 3 - //~^^ NOTE the following parameter types were expected + //~| NOTE the following parameter types were expected //~| NOTE expected 4 parameters } From ded0d512dc663c774d849cd9836212ff69e56f5c Mon Sep 17 00:00:00 2001 From: William Lee Date: Thu, 4 Aug 2016 08:28:48 -0400 Subject: [PATCH 3/3] Removing trailing whitespace leftover from last re-formatting commit --- src/test/compile-fail/E0060.rs | 2 +- src/test/compile-fail/E0061.rs | 2 +- src/test/compile-fail/issue-18819.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/compile-fail/E0060.rs b/src/test/compile-fail/E0060.rs index 342ad3f2148ae..e1f2618c180f6 100644 --- a/src/test/compile-fail/E0060.rs +++ b/src/test/compile-fail/E0060.rs @@ -13,7 +13,7 @@ extern "C" { } fn main() { - unsafe { printf(); } + unsafe { printf(); } //~^ ERROR E0060 //~| NOTE expected at least 1 parameter //~| NOTE the following parameter type was expected diff --git a/src/test/compile-fail/E0061.rs b/src/test/compile-fail/E0061.rs index 83b32200019f5..ca04b059dc7f6 100644 --- a/src/test/compile-fail/E0061.rs +++ b/src/test/compile-fail/E0061.rs @@ -12,7 +12,7 @@ fn f(a: u16, b: &str) {} fn main() { f(0); - //~^ ERROR E0061 + //~^ ERROR E0061 //~| NOTE expected 2 parameters //~| NOTE the following parameter types were expected } diff --git a/src/test/compile-fail/issue-18819.rs b/src/test/compile-fail/issue-18819.rs index 0310b4ea75fe1..cf650460c3de1 100644 --- a/src/test/compile-fail/issue-18819.rs +++ b/src/test/compile-fail/issue-18819.rs @@ -23,7 +23,7 @@ fn print_x(_: &Foo, extra: &str) { } fn main() { - print_x(X); + print_x(X); //~^ ERROR this function takes 2 parameters but 1 parameter was supplied //~| NOTE the following parameter types were expected: &Foo, &str //~| NOTE expected 2 parameters