Skip to content

Commit

Permalink
add example of clone supertrait relaxation
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtwco committed Dec 12, 2024
1 parent 7a11fe9 commit 762c6d8
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions text/3729-sized-hierarchy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1097,10 +1097,22 @@ in the next next edition.
[why-use-const-traits]: #why-use-const-traits

Previous iterations of this RFC had both linear[^9] and non-linear[^10] trait hierarchies
which included a `RuntimeSized` trait and did not use const traits. However, both of
these were found to be backwards-incompatible due to being unable to relax the
supertrait of `Clone`. Without const traits, it is not possible to represent
runtime-sized types.
which included a `RuntimeSized` trait and did not use const traits.

However, both of these were found to be backwards-incompatible due to being unable
to relax the supertrait of `Clone`. In the example below, `Foo::uses_supertrait_bound`'s
call to `requires_sized` relies on `Clone` having a `Sized` supertrait and would no
longer compile if `Clone`'s supertrait was relaxed:

```rust
trait Foo: Clone {
fn uses_supertrait_bound() { requires_sized::<Self>() }
}

fn requires_sized<T: Sized>() { /* ... */ }
```

Therefore, without const traits it is not possible to represent runtime-sized types.

[^9]: In previous iterations, the proposed linear trait hierarchy was:

Expand Down

0 comments on commit 762c6d8

Please sign in to comment.