-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suggestion: Add a compiler indication for "get the same type that that variable has" #3241
Comments
Do you mean something like |
Yes, but without being a run-time function that slows down performance |
Type info in rust is (mostly) all removed at compile time, so this would be a compile time only operation. |
I get your point but just to clarify, But is there anything you need that cannot be achieved with existential types? let mut ram: Vec<u32> = Vec::new();
type T;
let _: &T = &ram;
let mut result: Vec<T> = Vec::new(); |
Your example of using this typeof in return type is ambiguous in the presence of multiple bindings of the same name within a function: fn unfun() -> t# declared_multiple_times {
let declared_multiple_times = 1;
let declared_multiple_times = "1";
generic_return_fn() // could return an i32, &'static str, and possibly others
} It also goes against the spirit of type signatures of items not being inferred. |
What I mean is (for example) add a t# before a variable to get that type, instead of using a function that slows performance, the compiler gets the same type of that variable.
Example
Example of how this may work.
This is just a quick example I made up from a real code I'm using, but it would be really useful if the first thing you could see is the same type that another without using the
type
keyword for only two variables.This addition could improve readability without losing performance, because it just adds a little bit of time at compile time.
Thanks for reading, that is my suggestion.
The text was updated successfully, but these errors were encountered: