Skip to content

Commit 1167e58

Browse files
Clarify "weak"/"strong"
1 parent d0c32f3 commit 1167e58

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

text/3437-implementable-trait-alias.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ Extend `#![feature(trait_alias)]` to permit `impl` blocks for trait aliases with
99

1010
# Motivation
1111

12-
Often, one desires to have a "weak" version of a trait, as well as a "strong" one providing additional guarantees. Subtrait relationships are commonly used for this, but they sometimes fall short—especially when the "strong" version is expected to see more use, or was stabilized first.
12+
Often, one desires to have a "weak" version of a trait, as well as a "strong" one providing additional guarantees. Specifically, this RFC addresses trait relationships with the following properties:
13+
14+
- For any implementation of the "strong" variant, there is exactly one way to implement the "weak" variant.
15+
- For any implementation of the "weak" variant, there is at most one way to implement the "strong" variant.
16+
17+
Subtrait relationships are commonly used to model this, but this often leads to coherence and backward compatibility issues—especially when the "strong" version is expected to see more use, or was stabilized first.
1318

1419
## Example: AFIT `Send` bound aliases
1520

@@ -121,7 +126,7 @@ error[E0404]: expected trait, found trait alias `Frobber`
121126

122127
*This example relies on some language features that are currently pure speculation. Implementable trait aliases are potentially necessary to support this use-case, but not sufficient.*
123128

124-
Ever since the GAT MVP was stabilized, there has been discussion about how to add `LendingIterator` to the standard library, without breaking existing uses of `Iterator`. The relationship between `LendingIterator` and `Iterator` is "weak"/"strong"an `Iterator` is a `LendingIterator` with some extra guarantees about the `Item` associated type.
129+
Ever since the GAT MVP was stabilized, there has been discussion about how to add `LendingIterator` to the standard library, without breaking existing uses of `Iterator`. The relationship between `LendingIterator` and `Iterator` is "weak"/"strong"; an `Iterator` is a `LendingIterator` with an extra guarantee about its `Item` associated type (namely, that it is bivariant in its lifetime parameter).
125130

126131
Now, let's imagine that Rust had some form of "variance bounds", that allowed restricting the way in which a type's GAT can depend on said GAT's generic parameters. One could then define `Iterator` in terms of `LendingIterator`, like so:
127132

0 commit comments

Comments
 (0)