Skip to content

Commit 4e138b3

Browse files
committed
mention implicit Sized bound in more places
Mention that there is an implicit `Sized` bound on associated types as well as on type parameters. Make it more clear that `?Sized` relaxes the implicit `Sized` bound. Also fix some grammar issues where omitted words caused confusion.
1 parent 7ab0256 commit 4e138b3

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/dynamically-sized-types.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ types">DSTs</abbr>. Such types can only be used in certain cases:
1111
* Pointers to slices also store the number of elements of the slice.
1212
* Pointers to trait objects also store a pointer to a vtable.
1313
* <abbr title="dynamically sized types">DSTs</abbr> can be provided as
14-
type arguments when a bound of `?Sized`. By default any type parameter
15-
has a `Sized` bound.
14+
type arguments to generic type parameters having the special `?Sized` bound.
15+
They can also be used for associated type definitions when the corresponding associated type declaration has a `?Sized` bound.
16+
By default, any type parameter or associated type has a `Sized` bound, unless it is relaxed using `?Sized`.
1617
* Traits may be implemented for <abbr title="dynamically sized
17-
types">DSTs</abbr>. Unlike type parameters `Self: ?Sized` by default in trait
18-
definitions.
18+
types">DSTs</abbr>.
19+
Unlike with generic type parameters, `Self: ?Sized` is the default in trait definitions.
1920
* Structs may contain a <abbr title="dynamically sized type">DST</abbr> as the
2021
last field, this makes the struct itself a
2122
<abbr title="dynamically sized type">DST</abbr>.

src/items/associated-items.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ finally an optional list of trait bounds.
210210

211211
The identifier is the name of the declared type alias. The optional trait bounds
212212
must be fulfilled by the implementations of the type alias.
213+
There is an implicit [`Sized`] bound on associated types that can be relaxed using the special `?Sized` bound.
213214

214215
An *associated type definition* defines a type alias on another type. It is
215216
written as `type`, then an [identifier], then an `=`, and finally a [type].
@@ -344,6 +345,7 @@ fn main() {
344345
[`Box<Self>`]: ../special-types-and-traits.md#boxt
345346
[`Pin<P>`]: ../special-types-and-traits.md#pinp
346347
[`Rc<Self>`]: ../special-types-and-traits.md#rct
348+
[`Sized`]: ../special-types-and-traits.md#sized
347349
[traits]: traits.md
348350
[type aliases]: type-aliases.md
349351
[inherent implementations]: implementations.md#inherent-implementations

src/special-types-and-traits.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ UnwindSafe>` is a valid type.
134134

135135
## `Sized`
136136

137-
The [`Sized`] trait indicates that the size of this type is known at
138-
compile-time; that is, it's not a [dynamically sized type]. [Type parameters]
139-
are `Sized` by default. `Sized` is always implemented automatically by the
140-
compiler, not by [implementation items].
137+
The [`Sized`] trait indicates that the size of this type is known at compile-time; that is, it's not a [dynamically sized type].
138+
[Type parameters] are `Sized` by default, as are [associated types].
139+
`Sized` is always implemented automatically by the compiler, not by [implementation items].
140+
These implicit `Sized` bounds may be relaxed by using the special `?Sized` bound.
141141

142142
[`Arc<Self>`]: ../std/sync/struct.Arc.html
143143
[`Box<T>`]: ../std/boxed/struct.Box.html
@@ -160,6 +160,7 @@ compiler, not by [implementation items].
160160
[`Unpin`]: ../std/marker/trait.Unpin.html
161161

162162
[Arrays]: types/array.md
163+
[associated types]: items/associated-items.md#associated-types
163164
[call expressions]: expressions/call-expr.md
164165
[deref coercions]: type-coercions.md#coercion-types
165166
[dereference operator]: expressions/operator-expr.md#the-dereference-operator

src/trait-bounds.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ Trait and lifetime bounds are also used to name [trait objects].
7777

7878
## `?Sized`
7979

80-
`?` is only used to declare that the [`Sized`] trait may not be
81-
implemented for a type parameter or associated type. `?Sized` may
82-
not be used as a bound for other types.
80+
`?` is only used to relax the implicit [`Sized`] trait bound for [type parameters] or [associated types].
81+
`?Sized` may not be used as a bound for other types.
8382

8483
## Lifetime bounds
8584

@@ -149,4 +148,5 @@ fn call_on_ref_zero<F>(f: F) where F: for<'a> Fn(&'a i32) {
149148
[generic]: items/generics.md
150149
[Trait]: items/traits.md#trait-bounds
151150
[trait objects]: types/trait-object.md
151+
[type parameters]: types/parameters.md
152152
[where clause]: items/generics.md#where-clauses

0 commit comments

Comments
 (0)