Is rust analizer lying? infer variable to a captering closure

Hello world,
this is odd
the first snip of code should not be aloud ( i think)

let a = 1000f32 ;
    let clos = || a*0.1f32; // clos is infered as impl Fn() -> f32t says analyzer

but when i type -which should be the same -, i get the right error

let clo2: impl Fn() -> f32 = || a*0.1f32;

compiler magic? what is the type of clos?


You get an error, because you can't use impl Trait in as type annotation in a let binding. Your closure does implement Fn() -> f32 though. As to why Rust analyzer displays impl Fn() -> f32 as type hint instead of the concrete type of the closure (which looks something like [closure@src/ 3:18]), I assume it is because it is deemed more helpful by most Rust users.

Edit: I think I found the issue and PR for this feature:


If you don't use impl Fn() -> f32, what else can be written as an owned type here?

The trait object needs a pointer which is not the case here.

The syntax is already designed:


okay guys tnx so far