Skip to content

Commit f183df7

Browse files
committed
Update from review.
1 parent b3d68ee commit f183df7

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/items/associated-items.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,28 @@ Associated functions whose first parameter is named `self` are called *methods*
9898
and may be invoked using the [method call operator], for example, `x.foo()`, as
9999
well as the usual function call notation.
100100

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):
103104

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+
```
111109

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.
114113

115114
```rust
116115
# use std::rc::Rc;
117116
# use std::sync::Arc;
118117
# use std::pin::Pin;
118+
// Examples of methods implemented on struct `Example`.
119119
struct Example;
120120
type Alias = Example;
121+
trait Trait { type Output; }
122+
impl Trait for Example { type Output = Example; }
121123
impl Example {
122124
fn by_value(self: Self) {}
123125
fn by_ref(self: &Self) {}
@@ -129,6 +131,7 @@ impl Example {
129131
fn explicit_type(self: Arc<Example>) {}
130132
fn with_lifetime<'a>(self: &'a Self) {}
131133
fn nested<'a>(self: &mut &'a Arc<Rc<Box<Alias>>>) {}
134+
fn via_projection(self: <Example as Trait>::Output) {}
132135
}
133136
```
134137

src/items/traits.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ trait TraitMethods {
126126
```
127127

128128
```rust,compile_fail
129-
// These are object-safe, but cannot be dispatched on a trait object.
129+
// This trait is object-safe, but these methods cannot be dispatched on a trait object.
130130
trait NonDispatchable {
131131
// Non-methods cannot be dispatched.
132132
fn foo() where Self: Sized {}
@@ -135,7 +135,6 @@ trait NonDispatchable {
135135
// `other` may be a different concrete type of the receiver.
136136
fn param(&self, other: Self) where Self: Sized {}
137137
// Generics are not compatible with vtables.
138-
// Alternate solution is to use a trait object instead.
139138
fn typed<T>(&self, x: T) where Self: Sized {}
140139
}
141140
@@ -178,7 +177,7 @@ let obj: Box<dyn TraitWithSize> = Box::new(S); // ERROR
178177
```
179178

180179
```rust,compile_fail
181-
// Not object safe if `Self` is a type parameter.
180+
// Not object safe if `Self` is a type argument.
182181
trait Super<A> {}
183182
trait WithSelf: Super<Self> where Self: Sized {}
184183

0 commit comments

Comments
 (0)