Closed
Description
A minimal complete test case:
fn takes_callback<F,T,R>(callback: F, t: T)
where F: FnOnce(T) -> R
{
callback(t);
}
fn callback(s1: &str, s2: &str) {
println!("Hello {} {}", s1, s2);
}
fn main() {
takes_callback(callback, "rust!");
}
Attempting to compile this under nightly gives the following:
mqudsi@ZBook /m/c/U/M/g/iMessageCore> rustc +nightly ./test.rs
error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
--> ./test.rs:12:5
|
12 | takes_callback(callback, "rust!");
| ^^^^^^^^^^^^^^ expected function that takes 1 argument
|
= note: required by `takes_callback`
error: aborting due to previous error
The error E0593 is correct, a function is expected to take 1 argument but it takes 2 arguments. But the "function" that is failing this expectation/test is not takes_callback
but rather callback
.
The error message "expected function that takes 1 argument" in the diagram below the error points to takes_callback
which definitely was not expected to take only one argument (since it takes two arguments, FnOnce
and T
).
As best as I can tell, this error should be
mqudsi@ZBook /m/c/U/M/g/iMessageCore> rustc +nightly ./test.rs
error[E0593]: function is expected to take 1 argument, but it takes 2 arguments
--> ./test.rs:12:5
|
12 | takes_callback(callback, "rust!");
| ^^^^^ expected closure that takes 1 argument
|
= note: required by `takes_callback`
error: aborting due to previous error