Skip to content

mention implicit Sized bound in more places #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/dynamically-sized-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ types">DSTs</abbr>. Such types can only be used in certain cases:
* Pointers to slices also store the number of elements of the slice.
* Pointers to trait objects also store a pointer to a vtable.
* <abbr title="dynamically sized types">DSTs</abbr> can be provided as
type arguments when a bound of `?Sized`. By default any type parameter
has a `Sized` bound.
type arguments to generic type parameters having the special `?Sized` bound.
They can also be used for associated type definitions when the corresponding associated type declaration has a `?Sized` bound.
By default, any type parameter or associated type has a `Sized` bound, unless it is relaxed using `?Sized`.
* Traits may be implemented for <abbr title="dynamically sized
types">DSTs</abbr>. Unlike type parameters `Self: ?Sized` by default in trait
definitions.
types">DSTs</abbr>.
Unlike with generic type parameters, `Self: ?Sized` is the default in trait definitions.
* Structs may contain a <abbr title="dynamically sized type">DST</abbr> as the
last field, this makes the struct itself a
<abbr title="dynamically sized type">DST</abbr>.
Expand Down
2 changes: 2 additions & 0 deletions src/items/associated-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ finally an optional list of trait bounds.

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

An *associated type definition* defines a type alias on another type. It is
written as `type`, then an [identifier], then an `=`, and finally a [type].
Expand Down Expand Up @@ -344,6 +345,7 @@ fn main() {
[`Box<Self>`]: ../special-types-and-traits.md#boxt
[`Pin<P>`]: ../special-types-and-traits.md#pinp
[`Rc<Self>`]: ../special-types-and-traits.md#rct
[`Sized`]: ../special-types-and-traits.md#sized
[traits]: traits.md
[type aliases]: type-aliases.md
[inherent implementations]: implementations.md#inherent-implementations
Expand Down
9 changes: 5 additions & 4 deletions src/special-types-and-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ UnwindSafe>` is a valid type.

## `Sized`

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

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

[Arrays]: types/array.md
[associated types]: items/associated-items.md#associated-types
[call expressions]: expressions/call-expr.md
[deref coercions]: type-coercions.md#coercion-types
[dereference operator]: expressions/operator-expr.md#the-dereference-operator
Expand Down
6 changes: 3 additions & 3 deletions src/trait-bounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ Trait and lifetime bounds are also used to name [trait objects].

## `?Sized`

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

## Lifetime bounds

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