Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E0060 and E0061 improvement #35983

Merged
merged 1 commit into from
Sep 6, 2016
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
20 changes: 11 additions & 9 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2481,16 +2481,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
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::<Vec<String>>();
if input_types.len() > 0 {
err.note(&format!("the following parameter type{} expected: {}",
if expected_count == 1 {" was"} else {"s were"},
input_types.join(", ")));
if input_types.len() > 1 {
err.note("the following parameter types were expected:");
err.note(&input_types.join(", "));
} else if input_types.len() > 0 {
err.note(&format!("the following parameter type was expected: {}",
input_types[0]));
} else {
err.span_label(sp, &format!("expected {}{} parameter{}",
if variadic {"at least "} else {""},
expected_count,
if expected_count == 1 {""} else {"s"}));
}
err.emit();
}
Expand Down
3 changes: 1 addition & 2 deletions src/test/compile-fail/E0060.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ extern "C" {
fn main() {
unsafe { printf(); }
//~^ ERROR E0060
//~| NOTE expected at least 1 parameter
//~| NOTE the following parameter type was expected
//~| NOTE the following parameter type was expected: *const u8
}
10 changes: 8 additions & 2 deletions src/test/compile-fail/E0061.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@

fn f(a: u16, b: &str) {}

fn f2(a: u16) {}

fn main() {
f(0);
//~^ ERROR E0061
//~| NOTE expected 2 parameters
//~| NOTE the following parameter types were expected
//~| NOTE the following parameter types were expected:
//~| NOTE u16, &str

f2();
//~^ ERROR E0061
//~| NOTE the following parameter type was expected: u16
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/issue-18819.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ fn print_x(_: &Foo<Item=bool>, 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<Item=bool>, &str
//~| NOTE expected 2 parameters
//~| NOTE the following parameter types were expected:
//~| NOTE &Foo<Item=bool>, &str
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-3044.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//~| NOTE _, _
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sigh, this one got worse. I wish I'd fixed the type variable names also. Once they're fixed, this should look better

// the first error is, um, non-ideal.
}
1 change: 0 additions & 1 deletion src/test/compile-fail/issue-4935.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ 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
3 changes: 1 addition & 2 deletions src/test/compile-fail/method-call-err-msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ fn main() {
//~^ 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
//~| NOTE isize, isize

let y = Foo;
y.zero()
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/not-enough-arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 expected 4 parameters
//~| NOTE the following parameter types were expected:
//~| NOTE isize, isize, isize, isize
}
2 changes: 0 additions & 2 deletions src/test/compile-fail/overloaded-calls-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ 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
}
8 changes: 4 additions & 4 deletions src/test/compile-fail/variadic-ffi-3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ extern "C" fn bar(f: isize, x: u8) {}
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
//~^ NOTE the following parameter types were expected:
//~| NOTE isize, u8
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
//~^ NOTE the following parameter types were expected:
//~| NOTE isize, u8

let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
//~^ ERROR: mismatched types
Expand Down