Skip to content

Commit

Permalink
Merge pull request #1427 from mattheww/2023-11_lone_self
Browse files Browse the repository at this point in the history
Lone `self` in a method body resolves to the self parameter
  • Loading branch information
ehuss authored Nov 21, 2023
2 parents 6a66f10 + e8ddd3c commit 75d2d5d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/paths.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,20 @@ mod b {
`self` resolves the path relative to the current module. `self` can only be used as the
first segment, without a preceding `::`.

In a method body, a path which consists of a single `self` segment resolves to the method's self parameter.


```rust
fn foo() {}
fn bar() {
self::foo();
}
struct S(bool);
impl S {
fn baz(self) {
self.0;
}
}
# fn main() {}
```

Expand Down

0 comments on commit 75d2d5d

Please sign in to comment.