@@ -355,6 +355,10 @@ pub trait Iterator = for<'a> LendingIterator<Item<'a> = <Self as Iterator>::Item
355355}
356356```
357357
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+
358362## Implementing trait aliases for multiple traits
359363
360364Trait 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.
634638## Bodies for trait aliases
635639
636640Trait 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.
638644
639645### ` type ` s and ` const ` alias items in trait alias bodies
640646
@@ -672,13 +678,9 @@ trait FooBar = Foo + Bar {
672678```
673679
674680As 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.
678682
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:
682684
683685``` rust
684686trait Foo {
@@ -697,9 +699,8 @@ impl Alias for () {
697699}
698700```
699701
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
703704[ ` TryFuture ` ] ( https://docs.rs/futures-core/latest/futures_core/future/trait.TryFuture.html )
704705as an implementable trait alias:
705706
@@ -729,23 +730,9 @@ impl TryFuture for AlwaysFails {
729730}
730731```
731732
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-
744733#### GATs in type alias bodies
745734
746- Type alias bodies can also contain GAT alias items. These are also subject to
747- the implementability rules, though reordering generic parameters does not
748- inhibit implementability.
735+ Type alias bodies can also contain GAT alias items:
749736
750737``` rust
751738trait Foo {
@@ -755,9 +742,9 @@ trait Foo {
755742}
756743
757744trait Alias = Foo {
758- type Tag <'a , U , T > = Self :: Gat <'a , T , U >; // Implementable
759- type GatVec <'a , T , U > = Self :: Gat <'a , Vec <T >, U >; // Not implementable
760- type GatSame <'a , T > = Self :: Gat <'a , T , T >; // Not implementable
745+ type Tag <'a , U , T > = Self :: Gat <'a , T , U >;
746+ type GatVec <'a , T , U > = Self :: Gat <'a , Vec <T >, U >;
747+ type GatSame <'a , T > = Self :: Gat <'a , T , T >;
761748}
762749```
763750
@@ -784,8 +771,8 @@ trait Alias = Frob {
784771Modifiers like ` const ` , ` async ` , ` unsafe ` , or ` extern "C" ` are neither required
785772nor accepted.
786773
787- You are allowed to specify generic parameters, in order to reorder them. But you
788- don't have to:
774+ You are allowed to specify the generic parameters, in order to reorder them. But
775+ you don't have to:
789776
790777``` rust
791778trait Frob {
@@ -917,7 +904,7 @@ It's this last issue especially that leads me to not relegate this to a future
917904possibility. Adding a defaulted item to a trait should at most require minor
918905changes to dependents, and restructuring a large ` impl ` block is not “minor”.
919906
920- ## No non-implementable items in trait alias bodies
907+ ## No non-implementable ` fn ` s` in trait alias bodies
921908
922909Such items don't have much utility from a backward-compatibility perspective,
923910and overlap with extension traits. However, the cost of allowing them is very
0 commit comments