You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/expressions/method-call-expr.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -25,12 +25,12 @@ The following procedure is used:
25
25
26
26
r[expr.method.candidate-receivers]
27
27
The first step is to build a list of candidate receiver types.
28
-
Obtain these by repeatedly [dereferencing][dereference] the receiver expression's type, adding each type encountered to the list, then finally attempting an [unsized coercion][coerce.unsize] at the end, and adding the result type if that is successful.
28
+
Obtain these by repeatedly [dereferencing][dereference] the receiver expression's type, adding each type encountered to the list, then finally attempting an [unsizing coercion][coerce.unsize] at the end, and adding the result type if that is successful.
29
29
30
30
r[expr.method.candidate-receivers-refs]
31
31
Then, for each candidate `T`, add `&T` and `&mut T` to the list immediately after `T`.
32
32
33
-
For instance, if the receiver has type `Box<[i32;2]>`, then the candidate types will be `Box<[i32;2]>`, `&Box<[i32;2]>`, `&mut Box<[i32;2]>`, `[i32; 2]` (by dereferencing), `&[i32; 2]`, `&mut [i32; 2]`, `[i32]` (by unsized coercion), `&[i32]`, and finally `&mut [i32]`.
33
+
For instance, if the receiver has type `Box<[i32;2]>`, then the candidate types will be `Box<[i32;2]>`, `&Box<[i32;2]>`, `&mut Box<[i32;2]>`, `[i32; 2]` (by dereferencing), `&[i32; 2]`, `&mut [i32; 2]`, `[i32]` (by unsizing coercion), `&[i32]`, and finally `&mut [i32]`.
34
34
35
35
r[expr.method.candidate-search]
36
36
Then, for each candidate type `T`, search for a [visible] method with a receiver of that type in the following places:
See [unsizedcoercion](#unsized-coercions) formoredetails.
144
+
See [unsizingcoercion](#unsizing-coercions) formoredetails.
145
145
146
146
r[coerce.types.deref]
147
147
* `&T` or `&mutT` to `&U` if `T` implements `Deref<Target=U>`.Forexample:
@@ -182,11 +182,11 @@ r[coerce.types.never]
182
182
*`!` to any `T`
183
183
184
184
r[coerce.unsize]
185
-
### Unsized Coercions
185
+
### Unsizing Coercions
186
186
187
187
r[coerce.unsize.intro]
188
-
The following coercions are called "unsized coercions", since their targets contain an unsized type.
189
-
unsized coercions apply to pointer-like types which point to types which can lose some of their compile-time known information (such as size or implemented traits). For example:
188
+
The following coercions are called "Unsizing coercions", since their targets contain an unsized type.
189
+
Unsizing coercions apply to pointer-like types which point to types which can lose some of their compile-time known information (such as size or implemented traits). For example:
190
190
191
191
```rust
192
192
usestd::cell::Cell;
@@ -224,12 +224,12 @@ fn main() {
224
224
225
225
r[coerce.unsize.confusion]
226
226
> [!NOTE]
227
-
> The term "unsized" might be quite confusing, since the coercion works on sized types (pointers) and the source pointer might point to an unsized type in the first place (`&dyn A -> &dyn Super` in the example above).
227
+
> The term "unsizing" might be quite confusing, since the coercion works on sized types (pointers) and the source pointer might point to an unsized type in the first place (`&dyn A -> &dyn Super` in the example above).
228
228
>
229
-
> "unsized" refers to the main purpose of these coercions --- converting (pointers to) sized types to (pointers to) unsized types. The pointers being not the focus, since unsized types can't exist without them.
229
+
> "Unsizing" refers to the main purpose of these coercions --- converting (pointers to) sized types to (pointers to) unsized types. The pointers being not the focus, since unsized types can't exist without them.
230
230
231
231
r[coerce.unsize.metadata]
232
-
When performing unsized coercion, the pointer metadata type changes. For example, when unsized`&u32` to `&dyn Debug` metadate type changes from `()` to `DynMetadata<dyn Debug>` (note that exact metadata types are not yet stable). This can also lead to a change in the pointer size -- `&u32` is half the size of `&dyn Debug`.
232
+
When performing unsizing coercion, the pointer metadata type changes. For example, when unsizing`&u32` to `&dyn Debug` metadate type changes from `()` to `DynMetadata<dyn Debug>` (note that exact metadata types are not yet stable). This can also lead to a change in the pointer size -- `&u32` is half the size of `&dyn Debug`.
233
233
234
234
r[coerce.unsize.traits]
235
235
Three traits, [`Unsize`], [`CoerceUnsized`], and [`PinCoerceUnsized`] are used to assist in this process and expose it for library use.
[`CoerceUnsized`] represents the fact that a pointer-like type can be coerced to another pointer-like type, due to `Unsize` being implemented for their pointees. For example, `&T` implements `CoerceUnsized<&U>` when `T: Unsize<U>`.
242
242
243
243
r[coerce.unsize.traits.pin-coerce-unsized]
244
-
[`PinCoerceUnsized`] is an unsafe marker trait for pointer-like types unsized coercion of which does not break [`Pin`] guarantees. It is a requirement of the [`CoerceUnsized` implementation for `Pin`][coerce.unsize.coerce-unsized-impls.pin-pin]. That is, `&D: PinCoerceUnsized` implies `Pin<&T>: CoerceUnsized<Pin<&U>>`.
244
+
[`PinCoerceUnsized`] is an unsafe marker trait for pointer-like types unsizing coercion of which does not break [`Pin`] guarantees. It is a requirement of the [`CoerceUnsized` implementation for `Pin`][coerce.unsize.coerce-unsized-impls.pin-pin]. That is, `&D: PinCoerceUnsized` implies `Pin<&T>: CoerceUnsized<Pin<&U>>`.
245
245
246
246
The following implementations of [`Unsize`] are built-in:
0 commit comments