Skip to content

Commit 1eda14e

Browse files
E0060 and E0061 improvement
1 parent 308824a commit 1eda14e

File tree

10 files changed

+30
-27
lines changed

10 files changed

+30
-27
lines changed

src/librustc_typeck/check/mod.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -2481,16 +2481,18 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
24812481
if arg_count == 1 {" was"} else {"s were"}),
24822482
error_code);
24832483

2484-
err.span_label(sp, &format!("expected {}{} parameter{}",
2485-
if variadic {"at least "} else {""},
2486-
expected_count,
2487-
if expected_count == 1 {""} else {"s"}));
2488-
24892484
let input_types = fn_inputs.iter().map(|i| format!("{:?}", i)).collect::<Vec<String>>();
2490-
if input_types.len() > 0 {
2491-
err.note(&format!("the following parameter type{} expected: {}",
2492-
if expected_count == 1 {" was"} else {"s were"},
2493-
input_types.join(", ")));
2485+
if input_types.len() > 1 {
2486+
err.note("the following parameter types were expected:");
2487+
err.note(&input_types.join(", "));
2488+
} else if input_types.len() > 0 {
2489+
err.note(&format!("the following parameter type was expected: {}",
2490+
input_types[0]));
2491+
} else {
2492+
err.span_label(sp, &format!("expected {}{} parameter{}",
2493+
if variadic {"at least "} else {""},
2494+
expected_count,
2495+
if expected_count == 1 {""} else {"s"}));
24942496
}
24952497
err.emit();
24962498
}

src/test/compile-fail/E0060.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,5 @@ extern "C" {
1515
fn main() {
1616
unsafe { printf(); }
1717
//~^ ERROR E0060
18-
//~| NOTE expected at least 1 parameter
19-
//~| NOTE the following parameter type was expected
18+
//~| NOTE the following parameter type was expected: *const u8
2019
}

src/test/compile-fail/E0061.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@
1010

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

13+
fn f2(a: u16) {}
14+
1315
fn main() {
1416
f(0);
1517
//~^ ERROR E0061
16-
//~| NOTE expected 2 parameters
17-
//~| NOTE the following parameter types were expected
18+
//~| NOTE the following parameter types were expected:
19+
//~| NOTE u16, &str
20+
21+
f2();
22+
//~^ ERROR E0061
23+
//~| NOTE the following parameter type was expected: u16
1824
}

src/test/compile-fail/issue-18819.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ fn print_x(_: &Foo<Item=bool>, extra: &str) {
2525
fn main() {
2626
print_x(X);
2727
//~^ ERROR this function takes 2 parameters but 1 parameter was supplied
28-
//~| NOTE the following parameter types were expected: &Foo<Item=bool>, &str
29-
//~| NOTE expected 2 parameters
28+
//~| NOTE the following parameter types were expected:
29+
//~| NOTE &Foo<Item=bool>, &str
3030
}

src/test/compile-fail/issue-3044.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ fn main() {
1515
});
1616
//~^^ ERROR this function takes 2 parameters but 1 parameter was supplied
1717
//~| NOTE the following parameter types were expected
18-
//~| NOTE expected 2 parameters
18+
//~| NOTE _, _
1919
// the first error is, um, non-ideal.
2020
}

src/test/compile-fail/issue-4935.rs

-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ fn foo(a: usize) {}
1414
fn main() { foo(5, 6) }
1515
//~^ ERROR this function takes 1 parameter but 2 parameters were supplied
1616
//~| NOTE the following parameter type was expected
17-
//~| NOTE expected 1 parameter

src/test/compile-fail/method-call-err-msg.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ fn main() {
2323
//~^ NOTE expected 0 parameters
2424
.one() //~ ERROR this function takes 1 parameter but 0 parameters were supplied
2525
//~^ NOTE the following parameter type was expected
26-
//~| NOTE expected 1 parameter
2726
.two(0); //~ ERROR this function takes 2 parameters but 1 parameter was supplied
2827
//~^ NOTE the following parameter types were expected
29-
//~| NOTE expected 2 parameters
28+
//~| NOTE isize, isize
3029

3130
let y = Foo;
3231
y.zero()

src/test/compile-fail/not-enough-arguments.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ fn foo(a: isize, b: isize, c: isize, d:isize) {
1919
fn main() {
2020
foo(1, 2, 3);
2121
//~^ ERROR this function takes 4 parameters but 3
22-
//~| NOTE the following parameter types were expected
23-
//~| NOTE expected 4 parameters
22+
//~| NOTE the following parameter types were expected:
23+
//~| NOTE isize, isize, isize, isize
2424
}

src/test/compile-fail/overloaded-calls-bad.rs

-2
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ fn main() {
4242
let ans = s();
4343
//~^ ERROR this function takes 1 parameter but 0 parameters were supplied
4444
//~| NOTE the following parameter type was expected
45-
//~| NOTE expected 1 parameter
4645
let ans = s("burma", "shave");
4746
//~^ ERROR this function takes 1 parameter but 2 parameters were supplied
4847
//~| NOTE the following parameter type was expected
49-
//~| NOTE expected 1 parameter
5048
}

src/test/compile-fail/variadic-ffi-3.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ extern "C" fn bar(f: isize, x: u8) {}
1717
fn main() {
1818
unsafe {
1919
foo(); //~ ERROR: this function takes at least 2 parameters but 0 parameters were supplied
20-
//~^ NOTE the following parameter types were expected
21-
//~| NOTE expected at least 2 parameters
20+
//~^ NOTE the following parameter types were expected:
21+
//~| NOTE isize, u8
2222
foo(1); //~ ERROR: this function takes at least 2 parameters but 1 parameter was supplied
23-
//~^ NOTE the following parameter types were expected
24-
//~| NOTE expected at least 2 parameters
23+
//~^ NOTE the following parameter types were expected:
24+
//~| NOTE isize, u8
2525

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

0 commit comments

Comments
 (0)