Skip to content

Named Local Variable vs Local Variable #1832

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

Open
kordyte opened this issue May 20, 2025 · 0 comments
Open

Named Local Variable vs Local Variable #1832

kordyte opened this issue May 20, 2025 · 0 comments
Labels
Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.

Comments

@kordyte
Copy link

kordyte commented May 20, 2025

In the introduction to variables (https://doc.rust-lang.org/nightly/reference/variables.html#r-variable.intro) 'named local variables' are introduced. From that point on the text only refers to 'local variables'. I am left with some doubt whether they are referring to the same thing. I only found the phrase 'named local variables' once. Of course, a named local variable is a local variable, but are there unnamed local variables? They would need to be different to anonymous temporaries which are explicitly listed in the first paragraph.

If my understanding is correct, I think it would be clearer if the first paragraph did not use the word 'named' and just called them 'local variable' (and 'function parameter' now I am looking at it). You could then follow it up with a statement such as 'All local variables are provided names through a let statement', and something similar for function parameters.

It feels that there is also room to explicitly state what happens with something like let _ = ...... Does this introduce a variable? I don't know the definitive answer there, but the wildcard pattern says that it does not copy, move, or borrow. So if a variable was introduced it would remain in an uninitialized state despite having an initializer. So I think that this cannot be a variable and eliminates my front-runner for what an unnamed variable looked like!

@ehuss ehuss added the Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like. label May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Cleanup Improvements to existing language which is correct but not clear, or missing examples, or the like.
Projects
None yet
Development

No branches or pull requests

2 participants