Clarify wording
This commit is contained in:
parent
59eb0f085c
commit
8a533773d4
|
|
@ -26,9 +26,11 @@ fn loud_insert<K>(set: &mut HashSet<K>, item: K) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that in the `loud_insert` example, `HashSet<K>` is not the type of an
|
Note that in the `loud_insert` example, `HashSet<K>` is not the type
|
||||||
argument of the `loud_insert` function, it only *appears* in the argument type
|
of the `set` argument of `loud_insert`, it only *appears* in the
|
||||||
`&mut HashSet<K>`.
|
argument type `&mut HashSet<K>`: we care about every type appearing
|
||||||
|
in the function's header (the header is the signature without the return type),
|
||||||
|
not only types of the function's arguments.
|
||||||
|
|
||||||
The rationale for applying implied bounds to input types is that, for example,
|
The rationale for applying implied bounds to input types is that, for example,
|
||||||
in order to call the `loud_insert` function above, the programmer must have
|
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`.
|
||||||
|
|
||||||
Similarly, given the following trait declaration:
|
Similarly, given the following trait declaration:
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
trait Copy where Self: Clone {
|
trait Copy where Self: Clone { // desugared version of `Copy: Clone`
|
||||||
...
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
@ -75,11 +77,11 @@ fn fun_with_copy<T: Copy>(x: T) {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The rationale for implied bounds for traits is that if a type implements `Copy`,
|
The rationale for implied bounds for traits is that if a type implements
|
||||||
that is, if there exists an `impl Copy` for that type, there *ought* to exist
|
`Copy`, that is, if there exists an `impl Copy` for that type, there *ought*
|
||||||
an `impl Clone` for that type, otherwise the compiler would have reported an
|
to exist an `impl Clone` for that type, otherwise the compiler would have
|
||||||
error in the first place. So again, if we were forced to repeat the additionnal
|
reported an error in the first place. So again, if we were forced to repeat the
|
||||||
`where SomeType: Clone` everywhere whereas we already know that
|
additionnal `where SomeType: Clone` everywhere whereas we already know that
|
||||||
`SomeType: Copy` hold, we would kind of duplicate the verification work.
|
`SomeType: Copy` hold, we would kind of duplicate the verification work.
|
||||||
|
|
||||||
Implied bounds are not yet completely enforced in rustc, at the moment it only
|
Implied bounds are not yet completely enforced in rustc, at the moment it only
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue