Skip to content

Commit

Permalink
Add a section on relationship between bounds and wherebounds
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Oct 19, 2022
1 parent 3c8acda commit 7e9d1fd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/items/associated-items.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,8 @@ An *associated type declaration* declares a signature for associated type
definitions. It is written in one of the following forms, where `Assoc` is the
name of the associated type, `Params` is a comma-separated list of type,
lifetime or const parameters, `Bounds` is a plus-separated list of trait bounds
on the associated type, and `WhereBounds` is a comma-separated list of bounds on
parameters:
that the associated type must meet, and `WhereBounds` is a comma-separated list
of bounds that the parameters must meet:

<!-- ignore: illustrative example forms -->
```rust,ignore
Expand Down Expand Up @@ -337,6 +337,18 @@ impl<T> Container for Vec<T> {
}
```

### Relationship between `Bounds` and `WhereBounds`

In this example:

```rust
trait Example {
type Output<T>: Ord where T: Debug
}
```

Given a reference to the associated type like `<X as Example>::Output<Y>`, the associated type itself must be `Ord`, and the type `Y` must be `Debug`.

### Required where clauses on generic associated types

Generic associated type declarations on traits currently may require a list of
Expand Down

0 comments on commit 7e9d1fd

Please sign in to comment.