rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Show _ type

Open latot opened this issue 10 months ago • 5 comments

Hi! I think would be nice be able to see in the IDEs which type currently have the use of "", while some times is needed, I think some time is not always to guess what "" will be, for example on multiple map operations, we can use "_" because we know is implicit, but does not means also know well which is the type, specially if we change it in a prototype.

Also show this would helps readability!

latot avatar May 26 '25 19:05 latot

Not sure I understand, do you have an example?

lnicola avatar May 26 '25 19:05 lnicola

A simpler one:

let a: usize = vec![1, 2, 3];

// Ideally here, to show after the "_" the signature like "_ (usize)" or something like that
let b: Vec<_> = a
.into_iter()
.map(|x| x*x)
.collect()

latot avatar May 26 '25 21:05 latot

I think it'll be best if when hovering over a selection of type we'll show the real type, but unfortunately I'm not sure how to implement this, as we have no way to map between the TypeRefId to its inferred type.

ChayimFriedman2 avatar May 26 '25 21:05 ChayimFriedman2

D: no way!

I personally, like the idea of see the code and see everything that we need, specially if there is several _, some code have a lot of them, hovering would works better on code that do not use much _.

latot avatar May 26 '25 21:05 latot

@latot for this specific need:

let b= a.into_iter().map(|x| x * x).collect::<Vec<_>>();

VScode will show the correct type for b.

Not sure if this helps, and pretty sure you knew it already, but there it is.

ThomasCartier avatar Jun 04 '25 08:06 ThomasCartier

Duplicate of #11722.

roife avatar Jul 02 '25 06:07 roife