Open
Description
Code
struct S<T> {
f: fn(T) -> T,
}
fn main() {
let mut n = 0i32;
let s = S {
f: |x| x.clone(),
};
n = (s.f)(n);
}
Current output
error[E0282]: type annotations needed
--> src/main.rs:8:13
|
8 | f: |x| x.clone(),
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
8 | f: |x: /* Type */| x.clone(),
| ++++++++++++
Desired output
error[E0282]: type annotations needed
--> src/main.rs:8:13
|
8 | f: |x| x.clone(),
| ^ - type must be known at this point
|
help: consider giving this closure parameter an explicit type
|
8 | f: |x: /* Type */| x.clone(),
| ++++++++++++
|
help: consider calling the function directly
|
8 | f: |x| Clone::clone(&x),
Rationale and extra context
Calling the function directly gets rid of the "type annotations needed" error
Other cases
No response
Anything else?
No response