Interaction between operator traits and autoderef is unclear

Open
#839 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Documentation
Clarity
Needs clarification
Activity status
Stale
Tech stack
rust
Domain
documentation

Research direction

Start by reading the linked Rust Reference sections on method-call autoderef and array-expression desugaring, then use the linked playground to compare the compiler's behavior for s[i].m(). Done means the interaction between operator traits, mutable-place context, and autoderef is precisely explained in the Reference, consistent with the observed behavior and relevant to RFC 997.

Written by the indexing model from the issue text.

Description

While doing research for rust-lang/rfcs#997, I realized that the precise interaction between operator desugaring and method calls is unclear.

Consider s[i].m(). This is a method call expression, so we can follow the autoderef rules in order to work out what to call. But the interior expression is s[i], which might desugar to an index or index_mut call, conditionally depending on whether or not the context is for a mutable place or not. So is the receiver position of m() a mutable place context?

This playground illustrates the compiler's behaviour here quite well, but I don't know the right way to word it in the reference that actually reflects what goes on in the code.

Dominant language
Rust
Stars
1.6k
Forks
607
Avg merge
1d 1h
Merged PRs (30d)
12

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.

More from rust-lang/reference

All issues in rust-lang/reference

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.