rust-lang / rust-lang/reference

Named Local Variable vs Local Variable

Open
#1,832 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Language Cleanup
Dominant language
Rust
Stars
1.6k
Forks
607
PR merge metrics
PR metrics pending

Description

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!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the variables introduction at the linked Reference section and trace how it uses “named local variables,” “local variables,” and function parameters. Check the treatment of let _ = ... and anonymous temporaries in nearby Reference text. Done means the terminology and behavior are stated consistently, including whether let _ introduces a variable.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.