Skip to content

Commit 39cdd4f

Browse files
scalexmmark-i-m
authored andcommitted
Clarify wording
1 parent 2b8f3d4 commit 39cdd4f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/traits/implied-bounds.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ fn loud_insert<K>(set: &mut HashSet<K>, item: K) {
2626
}
2727
```
2828

29-
Note that in the `loud_insert` example, `HashSet<K>` is not the type of an
30-
argument of the `loud_insert` function, it only *appears* in the argument type
31-
`&mut HashSet<K>`.
29+
Note that in the `loud_insert` example, `HashSet<K>` is not the type
30+
of the `set` argument of `loud_insert`, it only *appears* in the
31+
argument type `&mut HashSet<K>`: we care about every type appearing
32+
in the function's header (the header is the signature without the return type),
33+
not only types of the function's arguments.
3234

3335
The rationale for applying implied bounds to input types is that, for example,
3436
in order to call the `loud_insert` function above, the programmer must have
@@ -52,7 +54,7 @@ arguments of their function. The same reasoning applies when using an `impl`.
5254

5355
Similarly, given the following trait declaration:
5456
```rust,ignore
55-
trait Copy where Self: Clone {
57+
trait Copy where Self: Clone { // desugared version of `Copy: Clone`
5658
...
5759
}
5860
```
@@ -75,11 +77,11 @@ fn fun_with_copy<T: Copy>(x: T) {
7577
}
7678
```
7779

78-
The rationale for implied bounds for traits is that if a type implements `Copy`,
79-
that is, if there exists an `impl Copy` for that type, there *ought* to exist
80-
an `impl Clone` for that type, otherwise the compiler would have reported an
81-
error in the first place. So again, if we were forced to repeat the additionnal
82-
`where SomeType: Clone` everywhere whereas we already know that
80+
The rationale for implied bounds for traits is that if a type implements
81+
`Copy`, that is, if there exists an `impl Copy` for that type, there *ought*
82+
to exist an `impl Clone` for that type, otherwise the compiler would have
83+
reported an error in the first place. So again, if we were forced to repeat the
84+
additionnal `where SomeType: Clone` everywhere whereas we already know that
8385
`SomeType: Copy` hold, we would kind of duplicate the verification work.
8486

8587
Implied bounds are not yet completely enforced in rustc, at the moment it only

0 commit comments

Comments
 (0)