rust-lang / rust-lang/reference

Clarify how types are constructed from function items

Open
#1,419 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 section on Function Item Types (section 10.1.11 in stable branch as of Oct 26 2023) states:

When referred to, a function item, or the constructor of a tuple-like struct or enum variant, yields a zero-sized value of its function item type. That type explicitly identifies the function - its name, its type arguments, and its early-bound lifetime arguments (but not its late-bound lifetime arguments, which are only assigned when the function is called)

IMO the wording could be more explicit (and should include the return type?). Perhaps something like this:

A function item's type is defined by the function's name, the type and order of the its arguments, its return type, and its early-bound lifetime arguments. Late-bound lifetime arguments are not part of a function item's type since they are assigned when the function is called.

I'm not an expert by any means, so I don't know if the above description is correct or omits additional helpful information. For example, a statement about generics might be helpful. I presume they're not part of the type -- in which case a statement such as "Generics are not part of a function item's type since a function declared with generics is a template and not a function item - it becomes a function item when instantiated with specific types".

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 Function Item Types section, identified as section 10.1.11 in the stable branch, and compare its current wording with Rust's rules for function item types. Confirm whether argument order, return types, early- and late-bound lifetimes, and generics belong in the explanation; done means the section states the construction rules accurately and clearly.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.