Skip to content

Commit 75d2d5d

Browse files
authored
Merge pull request #1427 from mattheww/2023-11_lone_self
Lone `self` in a method body resolves to the self parameter
2 parents 6a66f10 + e8ddd3c commit 75d2d5d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/paths.md

+9
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,20 @@ mod b {
202202
`self` resolves the path relative to the current module. `self` can only be used as the
203203
first segment, without a preceding `::`.
204204

205+
In a method body, a path which consists of a single `self` segment resolves to the method's self parameter.
206+
207+
205208
```rust
206209
fn foo() {}
207210
fn bar() {
208211
self::foo();
209212
}
213+
struct S(bool);
214+
impl S {
215+
fn baz(self) {
216+
self.0;
217+
}
218+
}
210219
# fn main() {}
211220
```
212221

0 commit comments

Comments
 (0)