@@ -98,26 +98,28 @@ Associated functions whose first parameter is named `self` are called *methods*
98
98
and may be invoked using the [ method call operator] , for example, ` x.foo() ` , as
99
99
well as the usual function call notation.
100
100
101
- If the type of the ` self ` parameter is specified, it is limited to one of the
102
- following types:
101
+ If the type of the ` self ` parameter is specified, it is limited to semantic
102
+ types generated by the following grammar (where ` 'lt ` denotes some arbitrary
103
+ lifetime):
103
104
104
- - ` Self `
105
- - ` &Self `
106
- - ` &mut Self `
107
- - [ ` Box<Self> ` ]
108
- - [ ` Rc<Self> ` ]
109
- - [ ` Arc<Self> ` ]
110
- - [ ` Pin<P> ` ] where ` P ` is one of the above types except ` Self ` .
105
+ ``` text
106
+ P = &'lt S | &'lt mut S | Box<S> | Rc<S> | Arc<S> | Pin<P>
107
+ S = Self | P
108
+ ```
111
109
112
- The ` Self ` term can be replaced with the type being implemented, including
113
- type aliases for the type, or any nested combination of the above types.
110
+ The ` Self ` terminal in this grammar is the semantic ` Self ` type and can be
111
+ replaced with the type being implemented, including type aliases or associated
112
+ type projections for the type.
114
113
115
114
``` rust
116
115
# use std :: rc :: Rc ;
117
116
# use std :: sync :: Arc ;
118
117
# use std :: pin :: Pin ;
118
+ // Examples of methods implemented on struct `Example`.
119
119
struct Example ;
120
120
type Alias = Example ;
121
+ trait Trait { type Output ; }
122
+ impl Trait for Example { type Output = Example ; }
121
123
impl Example {
122
124
fn by_value (self : Self ) {}
123
125
fn by_ref (self : & Self ) {}
@@ -129,6 +131,7 @@ impl Example {
129
131
fn explicit_type (self : Arc <Example >) {}
130
132
fn with_lifetime <'a >(self : & 'a Self ) {}
131
133
fn nested <'a >(self : & mut & 'a Arc <Rc <Box <Alias >>>) {}
134
+ fn via_projection (self : <Example as Trait >:: Output ) {}
132
135
}
133
136
```
134
137
0 commit comments