Skip to content
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

Add basic GATs reference information #1265

Merged
merged 11 commits into from
Oct 19, 2022
Prev Previous commit
Add a section on relationship between bounds and wherebounds
  • Loading branch information
jackh726 committed Oct 19, 2022
commit 6b9e4ffd539af7db5e27b6c829f120f827ef69a4
17 changes: 15 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,19 @@ impl<T> Container for Vec<T> {
}
```

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

In this example:

```rust
# use std::fmt::Debug;
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