paths.md: document standalone `self` in a method body

This commit is contained in:
Matthew Woodcraft 2023-11-19 20:07:26 +00:00
parent cd8193e972
commit e8ddd3cd6b
1 changed files with 9 additions and 0 deletions

View File

@ -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() {}
```