mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 07:44:10 +00:00
E0060 and E0061 improvement
This commit is contained in:
parent
308824acec
commit
1eda14e4c9
@ -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();
|
||||
}
|
||||
|
@ -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,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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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.
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user