Skip to content

Commit f81510c

Browse files
committed
Resolve multiple impl Trait question
1 parent e7e26ea commit f81510c

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

text/0000-impl-trait-type-aliases.md

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ Here, anything that makes use of `Foo` knows that `Foo::Assoc` implements `Debug
284284
# Reference-level explanation
285285
[reference-level-explanation]: #reference-level-explanation
286286

287-
Since RFC 2071 was accepted, the initial implementation of `existential type` [has already been completed](https://github.com/rust-lang/rust/pull/52024). This RFC would simply replace the syntax of `existential type`, from:
287+
Since RFC 2071 was accepted, the initial implementation of `existential type` [has already been completed](https://github.com/rust-lang/rust/pull/52024). This RFC would replace the syntax of `existential type`, from:
288288

289289
```rust
290290
existential type Foo: Bar;
@@ -296,7 +296,21 @@ to:
296296
type Foo = impl Bar;
297297
```
298298

299-
In addition, when documenting `impl Trait`, explanations of the feature would avoid type theoretic terminology (specifically "existential types") and prefer type inference language (if any technical description is needed at all).
299+
In addition, having multiple occurrences of `impl Trait` in a type alias or associated type is now permitted, where each occurrence is desugared into a separate inferred type. For example, the following alias:
300+
301+
```rust
302+
type Foo = Arc<impl Iterator<Item = impl Debug>>;
303+
```
304+
305+
would be desugared to the equivalent of:
306+
307+
```rust
308+
existential type _0: Debug;
309+
existential type _1: Iterator<Item = _0>;
310+
type Foo = Arc<_1>;
311+
```
312+
313+
Furthermore, when documenting `impl Trait`, explanations of the feature would avoid type theoretic terminology (specifically "existential types") and prefer type inference language (if any technical description is needed at all).
300314

301315
`impl Trait` type aliases may contain generic parameters just like any other type alias. The type alias must contain the same type parameters as its concrete type, except those implicitly captured in the scope (see [RFC 2071](https://github.com/rust-lang/rfcs/blob/master/text/2071-impl-trait-existential-types.md) for details).
302316

@@ -397,19 +411,4 @@ The other alternatives commonly given are:
397411
# Unresolved questions
398412
[unresolved-questions]: #unresolved-questions
399413

400-
- The restriction of type alias `impl Trait` to the forms that are currently possible with `existential trait` is potentially unnecessary. Although this was proposed to simplify the RFC by only changing syntax, it could be a better choice to allow `impl Trait` anywhere in a type alias (by desugaring each occurrence into a separate inferred type).
401-
402-
In this case, each occurrence of `impl Trait` would be desugared to a new existential type. For example,
403-
the following alias:
404-
405-
```rust
406-
type Foo = Arc<impl Iterator<Item = impl Debug>>;
407-
```
408-
409-
would be desugared to the equivalent of:
410-
411-
```rust
412-
existential type _0: Debug;
413-
existential type _1: Iterator<Item = _0>;
414-
type Foo = Arc<_1>;
415-
```
414+
None

0 commit comments

Comments
 (0)