Skip to content

Commit 7445331

Browse files
committed
Editorial nits
1 parent f87e527 commit 7445331

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/type-coercions.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ r[coerce.unsize]
186186

187187
r[coerce.unsize.intro]
188188
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:
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:
190190

191191
```rust
192192
use std::cell::Cell;
@@ -222,14 +222,13 @@ fn main() {
222222
}
223223
```
224224

225-
r[coerce.unsize.confusion]
226225
> [!NOTE]
227226
> 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).
228227
>
229228
> "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.
230229
231230
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`.
231+
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`.
233232

234233
r[coerce.unsize.traits]
235234
Three internal traits, [`Unsize`], [`CoerceUnsized`], and [`PinCoerceUnsized`] are used to assist in this process and expose it for library use.
@@ -241,22 +240,23 @@ r[coerce.unsize.traits.coerce-unsized]
241240
[`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>`.
242241

243242
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`. That is, `&D: PinCoerceUnsized` implies `Pin<&T>: CoerceUnsized<Pin<&U>>`.
243+
[`PinCoerceUnsized`] is an unsafe marker trait for pointer-like types, unsized coercion of which does not break [`Pin`] guarantees. [`PinCoerceUnsized`] being implemented for the pointer is a requirement of the `CoerceUnsized` implementation for `Pin`. That is, `&D: PinCoerceUnsized` implies `Pin<&T>: CoerceUnsized<Pin<&U>>`.
245244

245+
r[coerce.unsize.built-in]
246246
The following implementations of [`Unsize`] are built-in:
247247

248-
r[coerce.unsize.slice]
248+
r[coerce.unsize.built-in.slice]
249249
* `[T; n]: Unsize<[T]>`.
250250

251-
r[coerce.unsize.trait-object]
251+
r[coerce.unsize.built-in.trait-object]
252252
* `T: Unsize<dyn U>`, when `T` implements `U + Sized`, and `U` is [dyn compatible].
253253

254-
r[coerce.unsize.trait-upcast]
254+
r[coerce.unsize.built-in.trait-upcast]
255255
* `dyn Trait: Unsize<dyn Super>`, when `Super` is one of `Trait`'s [supertraits].
256256
* This allows dropping auto traits, i.e. `dyn Trait + Auto` to `dyn Super` is allowed.
257257
* This allows adding auto traits if the principal trait has the auto trait as a super trait, i.e. given `trait Trait: Super + Auto {}`, `dyn Trait` to `dyn Trait + Auto` or to `dyn Super + Auto` coercions are allowed.
258258

259-
r[coerce.unsize.composite]
259+
r[coerce.unsize.built-in.composite]
260260
* `S<T...>: Unsize<S<U...>>`, when:
261261
* `S` is a struct.
262262
* The type of the last field of `S<T...>` implements `Unsize<X>` where `X` is the type of the last field of `S<U...>`.
@@ -265,7 +265,7 @@ r[coerce.unsize.composite]
265265

266266
r[coerce.unsize.pointer]
267267
A type `S<T...>` *can* implement `CoerceUnsized<S<U...>>` if
268-
1. Only one field of `S<T...>` has different type than the same field of `S<U...>` (ignoring fields of type `PhantomData<_>`).
268+
1. Only one field of `S<T...>` has a different type than the same field of `S<U...>` (ignoring fields of type `PhantomData<_>`).
269269
2. ... and that field's type implements `CoerceUnsized<X>` where `X` is the type of the same field in `S<U,...>`.
270270

271271
This allows it to provide an unsized coercion to `S<U...>`.

0 commit comments

Comments
 (0)