Skip to content

Commit 7d101c2

Browse files
Const future possibilities
1 parent a9169d1 commit 7d101c2

File tree

1 file changed

+46
-4
lines changed

1 file changed

+46
-4
lines changed

text/3437-implementable-trait-alias.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,10 +949,6 @@ something when it does not.
949949

950950
# Future possibilities
951951

952-
- New kinds of bounds: anything that makes `where` clauses more powerful would
953-
make this feature more powerful as well.
954-
- Variance bounds could allow this feature to support backward-compatible
955-
GATification.
956952
- We could allow trait aliases to define their own defaults for `impl`s. One
957953
possibility is [the `default partial impl` syntax I suggested on
958954
IRLO](https://internals.rust-lang.org/t/idea-partial-impls/22706/).
@@ -973,3 +969,49 @@ something when it does not.
973969
- We could add an attribute for trait aliases to opt in to generating their own
974970
`dyn` type.
975971
- This could be prototyped as a proc macro.
972+
973+
## New kinds of bounds
974+
975+
Anything that makes `where` clauses more powerful would make this feature more
976+
powerful as well.
977+
978+
For example:
979+
980+
- If we could write bounds for the `const`ness of a method, that could allow
981+
emulating some of [const traits](https://github.com/rust-lang/rfcs/pull/3762)—or
982+
even form part of the desugaring for that feature:
983+
984+
```rust
985+
pub trait PartialEq<Rhs = Self>
986+
where
987+
Rhs: ?Sized,
988+
{
989+
fn eq(&self, other: &Rhs) -> bool;
990+
991+
fn ne(&self, other: &Rhs) -> bool {
992+
!(self.eq(other))
993+
}
994+
}
995+
996+
trait ConstPartialEq<Rhs> = PartialEq<Rhs>
997+
where
998+
Self::eq: const,
999+
Self::ne: const; // 🚲🏠
1000+
```
1001+
1002+
- If we could write a bound requiring that a GAT not use is lifetime, that could
1003+
enable retrofitting `LendingIterator` into `Iterator`:
1004+
1005+
```rust
1006+
pub trait LendingIterator {
1007+
type Item<'a>
1008+
where
1009+
Self: 'a;
1010+
1011+
fn next(&mut self) -> Option<Self::Item<'_>>;
1012+
}
1013+
1014+
pub trait Iterator = Iterator
1015+
where
1016+
for<'a> Self::Item<'a>: doesnt_depend_on<'a>; // 🚲🏠
1017+
```

0 commit comments

Comments
 (0)