rust-lang / rust-lang/rfcs

Autoref for temporaries in argument position

Open
#1,984 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

T-lang
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

I often see code like (a + b).cmp(&(c + d)). Both the self argument and the first method argument of cmp are reference types, but only the self argument automatically gets a reference taken.

I suggest that function and method arguments should also automatically get their address taken, if and only if they are temporaries. Rvalue references are copied if they are Copy and thus are then temporaries and get their address taken automatically

So the above example could now be (a + b).cmp(c + d).

Things allowed under this scheme

  • (a + b).cmp(c + d)
  • foo.cmp(&bar)
  • foo.cmp(&vec[42])

Things not allowed under this scheme

  • foo.cmp(bar) if bar is not a reference type or a Copy type
  • foo.cmp(vec[42]) if vec's elements are not references or a Copy type
    • e.g. if the vec elements are i32 this would be allowed, but not if they are String

Locations where to apply autoref

  • function arguments
  • index op argument
  • struct constructor field initialization expressions
  • tuple field initialization expressions
  • array element initialization expressions

Contributor guide

No contributing guide indexed for this repository

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 by reviewing the issue's allowed and disallowed examples and the listed locations where autoref would apply. Determine the language-semantics and implementation entry points for argument, index, struct, tuple, and array initialization handling; done means the proposal has an agreed design and coverage for each stated case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
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.