Skip to content

Commit d1398b2

Browse files
authored
Merge pull request #2 from Centril/rfc/associated-type-bounds-patch-1
Associated type bounds: Fix desugaring + other house keeping
2 parents 244d5aa + f279bac commit d1398b2

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

text/0000-associated-type-bounds.md

+24-14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
[summary]: #summary
88

99
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`.
1213

1314
# Motivation
1415
[motivation]: #motivation
@@ -85,21 +86,29 @@ impl<I: Clone + Iterator<Item: Clone>> Clone for Peekable<I> {
8586
# Reference-level explanation
8687
[reference-level-explanation]: #reference-level-explanation
8788

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`.
92102

93103
# Drawbacks
94104
[drawbacks]: #drawbacks
95105

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.
103112

104113
# Rationale and alternatives
105114
[alternatives]: #alternatives
@@ -113,4 +122,5 @@ The introduced form in this RFC is comparatively both shorter and clearer.
113122
# Unresolved questions
114123
[unresolved]: #unresolved-questions
115124

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

Comments
 (0)