Skip to content

Commit d0c32f3

Browse files
Alias associated items
1 parent c08f2b8 commit d0c32f3

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

text/3437-implementable-trait-alias.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,13 +359,14 @@ let _: IntIter<Item = u32> = [1_u32].into_iter(); // `Item = u32` is redundant,
359359
# Rationale and alternatives
360360

361361
- Very lightweight, with no new syntax forms. Compare "trait transformers" proposals, for example—they are generally much heavier.
362+
- However, trait transformers would also address more use-cases (for example, sync and async versions of a trait).
362363
- Better ergonomics compared to purely proc-macro based solutions.
363364
- One alternative is to allow marker traits or auto traits to appear in `+` bounds of implementable aliases.
364365
(For example, `trait Foo = Bar + Send;` could be made implementable).
365366
- This may make the implementablility rules more intuitive to some, as the distinction between `+ Send` and `where Self: Send` would no longer be present.
366367
- However, it also might make the rules less intuitive, as the symmetry with `impl` blocks would be broken.
367368
- Also, such a change might break the commutativity of `+`.
368-
- It could also make it less obvious which trait is being implemented.
369+
- It could also make it less obvious which trait is being implemented, versus required; are we implementing `Bar`, `Send`, or both?
369370
- Again, user feedback could help make this decision.
370371
- Another option is to require an attribute on implementable aliases; e.g. `#[implementable] trait Foo = ...`. This would make the otherwise-subtle implementability rules more explicit, at the cost of cluttering user code and the attribute namespace.
371372
- A previous version of this RFC required generic parameters of implementable trait aliases to be used as generic parameters of the alias's primary trait. This restriction was meant to avoid surprising errors:
@@ -456,3 +457,12 @@ Perhaps a more narrowly tailored version of this extension, in which both subtra
456457
- `trait Foo: Copy = Iterator;` could be allowed as an alternative to `trait Foo = Iterator where Self: Copy;`.
457458
- `impl Trait<Assoc = Ty> for Type { /* ... */ }` could be permitted in the future, to make the "copy-paste" rule of thumb work better.
458459
- The possible contents of `impl` bodies could be expanded, for example to support combining supertrait and subtrait implementations.
460+
- Trait aliases could be expanded to support associated items of their own. For example:
461+
462+
```rust
463+
trait FutIter = Iterator<Item: Future> {
464+
type ItemOut = <Self::Item as Future>::Output;
465+
}
466+
```
467+
468+
Type aliases might also want this capability.

0 commit comments

Comments
 (0)