7
7
[ summary ] : #summary
8
8
9
9
Introduce the bound form ` MyTrait<AssociatedType: Bounds> ` , permitted anywhere
10
- a bound of the form ` MyTrait<AssociatedType = T> ` would be allowed. This form
11
- desugars to ` MyTrait<AssociatedType = impl Bounds> ` .
10
+ a bound of the form ` MyTrait<AssociatedType = T> ` would be allowed. The bound
11
+ ` T: Trait<AssociatedType: Bounds> ` desugars to the bounds ` T: Trait ` and
12
+ ` <T as Trait>::AssociatedType: Bounds ` .
12
13
13
14
# Motivation
14
15
[ motivation ] : #motivation
@@ -85,21 +86,29 @@ impl<I: Clone + Iterator<Item: Clone>> Clone for Peekable<I> {
85
86
# Reference-level explanation
86
87
[ reference-level-explanation ] : #reference-level-explanation
87
88
88
- The surface syntax ` Trait<AssociatedType: Bounds> ` should desugar to
89
- ` Trait<AssociatedType = impl Bounds> ` anywhere it appears. This syntax
90
- does not introduce any new semantics that the availability of
91
- ` impl Bounds ` does not already introduce.
89
+ The surface syntax ` T: Trait<AssociatedType: Bounds> ` should always desugar
90
+ to a pair of bounds: ` T: Trait ` and ` <T as Trait>::AssociatedType: Bounds ` .
91
+ Rust currently allows both of those bounds anywhere a bound can currently appear;
92
+ the new syntax does not introduce any new semantics.
93
+
94
+ Additionally, the surface syntax ` impl Trait<AssociatedType: Bounds> ` turns
95
+ into a named type variable ` T ` , universal or existential depending on context,
96
+ with the usual bound ` T: Trait ` along with the added bound
97
+ ` <T as Trait>::AssociatedType: Bounds ` .
98
+
99
+ Meanwhile, the surface syntax ` dyn Trait<AssociatedType: Bounds> ` desugars into
100
+ ` dyn Trait<AssociatedType = T> ` where ` T ` is a named type variable ` T ` with the
101
+ bound ` T: Bounds ` .
92
102
93
103
# Drawbacks
94
104
[ drawbacks ] : #drawbacks
95
105
96
- With the introduction of the ` impl Trait ` syntax, Rust code can already
97
- express this using the desugared form. This proposal just introduces a
98
- simpler surface syntax that parallels other uses of bounds. As always,
99
- when introducing new syntactic forms, an increased burden is put on
100
- developers to know about and understand those forms, and this proposal
101
- is no different. However, we believe that the parallel to the use of bounds
102
- elsewhere makes this new syntax immediately recognizable and understandable.
106
+ Rust code can already express this using the desugared form. This proposal
107
+ just introduces a simpler surface syntax that parallels other uses of bounds.
108
+ As always, when introducing new syntactic forms, an increased burden is put on
109
+ developers to know about and understand those forms, and this proposal is no
110
+ different. However, we believe that the parallel to the use of bounds elsewhere
111
+ makes this new syntax immediately recognizable and understandable.
103
112
104
113
# Rationale and alternatives
105
114
[ alternatives ] : #alternatives
@@ -113,4 +122,5 @@ The introduced form in this RFC is comparatively both shorter and clearer.
113
122
# Unresolved questions
114
123
[ unresolved ] : #unresolved-questions
115
124
116
- - Does allowing this for ` dyn ` trait objects introduce any unforseen issues?
125
+ - Does allowing this for ` dyn ` trait objects introduce any unforseen issues?
126
+ This can be resolved during stabilization.
0 commit comments