-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
When working on trying to improve the performance of a rust codebase, it's important to be able to introspect the nature of types. While there are a number of aspects that one might want to explore (alignment, size, etc.) I think the most important of these is probably the size of a type to help decide between Option<T>
and Box<T>
or to figure out if pigeonholing is being used to make Option<T>
the same size as T
, etc.
Since these are all awesomely available as const functions that take a type but no value, it would be wonderful if the size of types could be visible (preferably directly in the hover info, or alternatively via a code action).
Since #10933 was merged I think it should be possible although it might also depend on #10825 (going by the title but not by the description) in order to evaluate constant expressions.
e.g. a step in the right direction would be to make it possible to do this myself in the IDE, by typing out the following:
const X: usize = core::mem::size_of::<i32>();
then hovering over X and seeing the result of the constant evaluation. Currently hovering over X
just shows const X: usize = core::mem::size_of::<CxxWString>
, but it would be beyond amazing if it could show (instead or in addition) the result of the evaluation (e.g. const X: usize = core::mem::size_of::<i32>(); // 4
).
Once that works, rust-analyzer could basically "write and evaluate" in the background an expression to get the size of any type T
when T
is hovered over to retrieve the size (either in advance or on-the-fly).
Taking a step back and looking at what I'm asking: would you like me to open a second PR to formally request "evaluate and display the result of compile-time constant expressions evaluating to primitive types" or is this PR sufficient?