-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Proposal - Better control for initialization #18204
Comments
How is initonce any different than leaving off the mut qualifier? Similarly, I don't see how the purpose of mustinit - that's exactly how the language behaves today. What's the motivation for making it optional? |
The purpose is that you can leave variable uninitialized and intiialize it only when you are ready. 'initonce' means that you initialize it only once and cannot change its value later. I am not good in Rust language, perhaps the Rust language already works this way ? :) |
let a;
...
a = 5;
//a = 6; <- error, immutable value. already works. Any attempts to use |
Yeah, these features already exist. |
And what about mutable variables ? |
Rust never allows use before initialization. |
If you want to leave a variable uninitialized but can't prove safety to the compiler, then you use an |
I see. |
The only thing impossible to do is to seal the mutable variable from other changes. |
That's identical to an immutable variable. They don't have to be initialized at declaration; they just need to be initialized before first use. |
Update cc to 1.1.22 This version of `cc` contains [a fix](https://github.com/rust-lang/cc-rs/releases/tag/cc-v1.1.22) to prevent spurious rebuilds. Hopefully this should help avoid the CI issues rustc has been having.
Idea of keywords for better controlling variables initialization.
Samples:
mustinit - Variable that must be initialized before used.
initonce - Variable that can be initialized only once and then cannot be changed. It doesn't require the variable to be initialized.
The text was updated successfully, but these errors were encountered: