You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/3437-implementable-trait-alias.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -359,13 +359,14 @@ let _: IntIter<Item = u32> = [1_u32].into_iter(); // `Item = u32` is redundant,
359
359
# Rationale and alternatives
360
360
361
361
- 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).
362
363
- Better ergonomics compared to purely proc-macro based solutions.
363
364
- One alternative is to allow marker traits or auto traits to appear in `+` bounds of implementable aliases.
364
365
(For example, `trait Foo = Bar + Send;` could be made implementable).
365
366
- This may make the implementablility rules more intuitive to some, as the distinction between `+ Send` and `where Self: Send` would no longer be present.
366
367
- However, it also might make the rules less intuitive, as the symmetry with `impl` blocks would be broken.
367
368
- 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?
369
370
- Again, user feedback could help make this decision.
370
371
- 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.
371
372
- 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
456
457
-`trait Foo: Copy = Iterator;` could be allowed as an alternative to `trait Foo = Iterator where Self: Copy;`.
457
458
-`impl Trait<Assoc = Ty> for Type { /* ... */ }` could be permitted in the future, to make the "copy-paste" rule of thumb work better.
458
459
- 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:
0 commit comments