rust-lang / rust-lang/reference

Values of path expressions

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

Nobody has claimed this yet.

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

Description

The "Path expressions" section says:

  • "A path used as an expression context denotes either a local variable or an item.", and

  • "Path expressions that resolve to local or static variables are place expressions, other paths are value expressions.".

But it doesn't say how to get from an item or a local variable to a value or a place.

First, it should be saying that the path which makes up the expression is resolved in the value namespace.

Then it needs to cover each kind of entity that can appear in the value namespace, and explain how to use one to get a value or a place (and so also determine the expression's type).

For example:

  • for a function item, the type is the corresponding function item type and the value is that type's unique member

  • for a constant item, the type is the Type from the ConstantItem and the value is obtained by evaluating the expression in the ConstantItem

  • for a static item, the type is the Type from the StaticItem and the place represents the memory location represented by that static item

For a path that resolves to a local variable (or function parameter) things aren't so simple.

I suggest a reasonable approach for the Reference's current depth would be something along the following lines:

  • acknowledge that the notion of evaluating an expression isn't defined in isolation, but relative to an evaluation context

  • say that at runtime the evaluation context contains (at least) a chain of activation frames, corresponding to the functions which have been called and have not yet returned

  • say that an activation frame for a function contains a map from the function's local bindings to memory locations which are allocated when the function is called

  • say that for a path expression which resolves to a local binding the type is that binding's type, and the place represents the memory location that binding maps to in the last activation frame in the chain (which is necessarily an activation frame for the function containing the path expression).

I see that at present there is some wording about activation frames in the "return expressions" section, though nothing in "Call expressions".

See also #949 and #1489, and ferrocene/specification#466 (which is an earlier writeup of this issue).

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 "Path expressions" section, then read the existing wording on activation frames in "return expressions" and the "Call expressions" section. Review related issues #949, #1489, and ferrocene/specification#466 before defining the needed scope. Done means the Reference explains value-namespace resolution, entity-specific values or places, and local-binding evaluation contexts consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.