@@ -602,10 +602,10 @@ To resolve these conflicts, you can use trait alias bodies, as described below.
602
602
603
603
## Bodies for trait aliases
604
604
605
- Trait aliases can now optionally contain a body, specifying aliases for various
606
- items. These can be types, constants, or functions.
605
+ Trait aliases can now optionally contain a body, which specifies various * alias
606
+ items* . These can be types, constants, or functions.
607
607
608
- ### ` type ` s and ` const ` items in trait alias bodies
608
+ ### ` type ` s and ` const ` alias items in trait alias bodies
609
609
610
610
``` rust
611
611
trait Foo {
@@ -622,8 +622,8 @@ trait Alias = Foo {
622
622
` <T as Alias>::AssocVec ` means the same thing as ` Vec<<T as Foo>::Assoc> ` , and
623
623
` <T as Alias>::ASSOC_PLUS_1 ` is equivalent to ` const { <T as Foo>::ASSOC + 1 } ` .
624
624
625
- Items defined in a trait alias body shadow items of the same name in a primary
626
- trait .
625
+ Alias items defined in a trait alias body shadow items of the same name in
626
+ primary traits .
627
627
628
628
``` rust
629
629
trait Foo {
@@ -640,6 +640,9 @@ trait FooBar = Foo + Bar {
640
640
}
641
641
```
642
642
643
+ As aliases, ` type ` and ` const ` alias items do not require or accept bounds or
644
+ ` where ` clauses; these are taken from the thing being aliased.
645
+
643
646
#### Implementability
644
647
645
648
To be implementable, a ` type ` or ` const ` alias item must obey certain
@@ -709,9 +712,9 @@ trait Bar = Foo<Assoc = Result<Self::Foo, Vec<Self::Foo>>> {
709
712
710
713
#### GATs in type alias bodies
711
714
712
- Type alias bodies can also contain GATs . These are also subject to the
713
- implementability rules, though reordering generic parameters does not inhibit
714
- implementability.
715
+ Type alias bodies can also contain GAT alias items . These are also subject to
716
+ the implementability rules, though reordering generic parameters does not
717
+ inhibit implementability.
715
718
716
719
``` rust
717
720
trait Foo {
@@ -727,12 +730,15 @@ trait Alias = Foo {
727
730
}
728
731
```
729
732
733
+ ### Bounds
734
+
730
735
### ` fn ` s in type alias bodies
731
736
732
737
#### Implementable ` fn ` s
733
738
734
- Trait alias bodies can also contain aliases for methods of its primary trait(s).
735
- This involves a new syntax form for implementable function aliases:
739
+ Trait alias bodies can also contain function alias items for methods of its
740
+ primary trait(s). This involves a new syntax form for implementable function
741
+ aliases:
736
742
737
743
``` rust
738
744
trait Frob {
@@ -744,7 +750,8 @@ trait Alias = Frob {
744
750
}
745
751
```
746
752
747
- Effect keywords like ` const ` , ` async ` , or ` unsafe ` do not need to be specified.
753
+ Effect keywords like ` const ` , ` async ` , or ` unsafe ` do not need to be specified,
754
+ and are not permitted.
748
755
749
756
You are allowed to specify generic parameters, in order to reorder them. But you
750
757
don't have to:
@@ -761,6 +768,9 @@ trait Alias = Frob {
761
768
}
762
769
```
763
770
771
+ Just like ` type ` alias items, implementable ` fn ` alias items neither require nor
772
+ accept ` where ` clauses or bounds of any sort.
773
+
764
774
#### Non-implementable ` fn ` s
765
775
766
776
A trait alias body can also contain non-alias ` fn ` s, with bodies. These are not
@@ -784,6 +794,10 @@ This is similar to defining an extension trait like
784
794
(One difference from extension traits is that trait aliases do not create their
785
795
own ` dyn ` types.)
786
796
797
+ These non-alias function items can specify ` where ` clauses and bounds like any
798
+ other function item. They also have the same default ` Sized ` bounds on their
799
+ generic type parameters.
800
+
787
801
## Interaction with ` dyn `
788
802
789
803
Trait aliases do not define their own ` dyn ` types. This RFC does not change that
0 commit comments