E0060 and E0061 improvement

This commit is contained in:
Guillaume Gomez 2016-08-25 13:06:38 +02:00
parent 308824acec
commit 1eda14e4c9
10 changed files with 30 additions and 27 deletions

View File

@ -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();
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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 _, _
// the first error is, um, non-ideal.
}

View File

@ -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

View File

@ -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()

View File

@ -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
}

View File

@ -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
}

View File

@ -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