Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

Open
mattheww opened this issue Nov 20, 2023 · 0 comments
Open

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

mattheww opened this issue Nov 20, 2023 · 0 comments

Comments

@mattheww
Copy link
Contributor

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 rust-lang/reference#1427

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant