From e8ddd3cd6bfac1bb58a6890fd217eb031d620773 Mon Sep 17 00:00:00 2001 From: Matthew Woodcraft Date: Sun, 19 Nov 2023 20:07:26 +0000 Subject: [PATCH] paths.md: document standalone `self` in a method body --- src/paths.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/paths.md b/src/paths.md index 9efbda701..30c076143 100644 --- a/src/paths.md +++ b/src/paths.md @@ -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() {} ```