@@ -355,6 +355,10 @@ pub trait Iterator = for<'a> LendingIterator<Item<'a> = <Self as Iterator>::Item
355
355
}
356
356
```
357
357
358
+ You’ll note that ` Iterator ` ’s body does not explicitly define ` Item ` . Instead,
359
+ it’s defined implicitly by the `for<'a> <Self as LendingIterator >::Item<'a> =
360
+ <Self as Iterator >::Item` clause in the alias definition.
361
+
358
362
## Implementing trait aliases for multiple traits
359
363
360
364
Trait aliases that combine multiple traits with ` + ` are also implementable:
@@ -634,7 +638,9 @@ To resolve these conflicts, you can use trait alias bodies, as described below.
634
638
## Bodies for trait aliases
635
639
636
640
Trait aliases can now optionally contain a body, which specifies various * alias
637
- items* . These can be types, constants, or functions.
641
+ items* . These can be types, constants, or functions. It must always be possible
642
+ to derive the value of these items from the implementations of the aliased
643
+ traits; compilation will fail otherwise.
638
644
639
645
### ` type ` s and ` const ` alias items in trait alias bodies
640
646
@@ -672,13 +678,9 @@ trait FooBar = Foo + Bar {
672
678
```
673
679
674
680
As aliases, ` type ` and ` const ` alias items neither require nor accept bounds or
675
- ` where ` clauses; these are taken from the thing being aliased.
676
-
677
- #### Implementability
681
+ ` where ` clauses; these are taken from the things being aliased.
678
682
679
- To be implementable, a ` type ` or ` const ` alias item must obey certain
680
- restrictions. It must either be set equal to an item of a primary trait of the
681
- alias:
683
+ ` type ` and ` const ` alias items may appear in implementations of the alias:
682
684
683
685
``` rust
684
686
trait Foo {
@@ -697,9 +699,8 @@ impl Alias for () {
697
699
}
698
700
```
699
701
700
- Or, the trait alias must set an associated type of the primary trait equal to a
701
- generic type, with the alias item as a generic parameter of that type. For
702
- example, here is
702
+ Alias items may be defined * implicitly* , through bounds on the trait alias
703
+ itself. For example, here is
703
704
[ ` TryFuture ` ] ( https://docs.rs/futures-core/latest/futures_core/future/trait.TryFuture.html )
704
705
as an implementable trait alias:
705
706
@@ -729,18 +730,6 @@ impl TryFuture for AlwaysFails {
729
730
}
730
731
```
731
732
732
- The generic parameter can also be nested:
733
-
734
- ``` rust
735
- trait Foo {
736
- type Assoc ;
737
- }
738
-
739
- trait Bar = Foo <Assoc = Result <Self :: Foo , Vec <Self :: Foo >>> {
740
- type Foo ;
741
- }
742
- ```
743
-
744
733
#### GATs in type alias bodies
745
734
746
735
Type alias bodies can also contain GAT alias items. These are also subject to
@@ -784,8 +773,8 @@ trait Alias = Frob {
784
773
Modifiers like ` const ` , ` async ` , ` unsafe ` , or ` extern "C" ` are neither required
785
774
nor accepted.
786
775
787
- You are allowed to specify generic parameters, in order to reorder them. But you
788
- don't have to:
776
+ You are allowed to specify the generic parameters, in order to reorder them. But
777
+ you don't have to:
789
778
790
779
``` rust
791
780
trait Frob {
0 commit comments