@@ -2431,26 +2431,28 @@ This error indicates that the `self` parameter in a method has an invalid
2431
2431
2432
2432
Methods take a special first parameter, of which there are three variants:
2433
2433
`self`, `&self`, and `&mut self`. These are syntactic sugar for
2434
- `self: Self`, `self: &Self`, and `self: &mut Self` respectively. The type
2435
- `Self` acts as an alias to the type of the current trait implementer, or
2436
- "receiver type". Besides the already mentioned `Self`, `&Self` and
2437
- `&mut Self` valid receiver types, the following are also valid:
2438
- `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
2439
- (where P is one of the previous types except `Self`).
2434
+ `self: Self`, `self: &Self`, and `self: &mut Self` respectively.
2440
2435
2441
2436
```
2442
2437
# struct Foo;
2443
2438
trait Trait {
2444
2439
fn foo(&self);
2440
+ // ^^^^^ `self` here is a reference to the receiver object
2445
2441
}
2446
2442
2447
2443
impl Trait for Foo {
2448
2444
fn foo(&self) {}
2449
- // ^^^^^ this the receiver type `&Foo`
2445
+ // ^^^^^ the receiver type is `&Foo`
2450
2446
}
2451
2447
```
2452
2448
2453
- The above is equivalent to:
2449
+ The type `Self` acts as an alias to the type of the current trait
2450
+ implementer, or "receiver type". Besides the already mentioned `Self`,
2451
+ `&Self` and `&mut Self` valid receiver types, the following are also valid:
2452
+ `self: Box<Self>`, `self: Rc<Self>`, `self: Arc<Self>`, and `self: Pin<P>`
2453
+ (where P is one of the previous types except `Self`). Note that `Self` can
2454
+ also be the underlying implementing type, like `Foo` in the following
2455
+ example:
2454
2456
2455
2457
```
2456
2458
# struct Foo;
0 commit comments