@@ -26,9 +26,11 @@ fn loud_insert<K>(set: &mut HashSet<K>, item: K) {
26
26
}
27
27
```
28
28
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.
32
34
33
35
The rationale for applying implied bounds to input types is that, for example,
34
36
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`.
52
54
53
55
Similarly, given the following trait declaration:
54
56
``` rust,ignore
55
- trait Copy where Self: Clone {
57
+ trait Copy where Self: Clone { // desugared version of `Copy: Clone`
56
58
...
57
59
}
58
60
```
@@ -75,11 +77,11 @@ fn fun_with_copy<T: Copy>(x: T) {
75
77
}
76
78
```
77
79
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
83
85
` SomeType: Copy ` hold, we would kind of duplicate the verification work.
84
86
85
87
Implied bounds are not yet completely enforced in rustc, at the moment it only
0 commit comments