rust-lang / rust-lang/fls

Lone `self` in a method body should resolve to the 'self parameter'

Open
#476 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-resolve C-bug
Dominant language
reStructuredText
Stars
497
Forks
41
Avg merge
3h 52m
Merged PRs (30d)
4

Description

In a method body, a path expression consisting only of the keyword self should resolve to the (binding of the) method's 'self parameter'.

I believe at the moment the FLS says this resolves to the containing module.

Example:

  struct MyType {
      x: (),
  }

  impl MyType {
      fn simple_method(self) {
          self.x;
      }
  }

Looking at the self.x FieldAccessExpression:

The part before the . is an UnqualifiedPathExpression whose single SimplePathSegment is the keyword self.

§14.9.4.2 "Path Expression Resolution" says (in fls_dc0yv4306p82) that we resolve the leftmost (and only) segment using general path resolution.

§14.9.4:12 (fls_ri50nc2dg7c4) says that a path segment which is the keyword self resolves to "the entity of the current module".

I've also filed https://github.com/rust-lang/reference/pull/1427

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 FLS §14.9.4, §14.9.4.2, and the cited anchors fls_ri50nc2dg7c4 and fls_dc0yv4306p82; compare the general path-resolution rule with the method-body example. Done means the specification clearly resolves a lone self path in a method body to the method's self parameter rather than the containing module.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.