@@ -85,7 +85,9 @@ immutable [`static` items].
85
85
The [ ` Send ` ] , [ ` Sync ` ] , [ ` UnwindSafe ` ] and [ ` RefUnwindSafe ` ] traits are _ auto
86
86
traits_ . Auto traits have special properties.
87
87
88
- First, auto traits are automatically implemented using the following rules:
88
+ If no explicit implementation or negative implementation is written out for an
89
+ auto trait for a given type, then the compiler implements it automatically
90
+ according to the following rules:
89
91
90
92
* ` &T ` , ` &mut T ` , ` *const T ` , ` *mut T ` , ` [T; n] ` and ` [T] ` implement the trait
91
93
if ` T ` does.
@@ -96,12 +98,23 @@ First, auto traits are automatically implemented using the following rules:
96
98
closure that captures a ` T ` by shared reference and a ` U ` by value implements
97
99
any auto traits that both ` &T ` and ` U ` do.
98
100
101
+ For generic types (counting the built-in types above as generic over ` T ` ), if an
102
+ generic implementation is available, then the compiler does not automatically
103
+ implement it for types that could use the implementation except that they do not
104
+ meet the requisite trait bounds. For instance, the standard library implements
105
+ ` Send ` for all ` &T ` where ` T ` is ` Sync ` ; this means that the compiler will not
106
+ implement ` Send ` for ` &T ` if ` T ` is ` Send ` but not ` Sync ` .
107
+
99
108
Auto traits can also have negative implementations, shown as `impl !AutoTrait
100
109
for T` in the standard library documentation, that override the automatic
101
110
implementations. For example ` *mut T ` has a negative implementation of ` Send ` ,
102
- and so ` *mut T ` and ` (*mut T,) ` are not ` Send ` . Finally, auto traits may
103
- be added as a bound to any [ trait object] \: ` Box<Debug + Send + UnwindSafe> ` is
104
- a valid type.
111
+ and so ` *mut T ` is not ` Send ` , even if ` T ` is. There is currently no stable way
112
+ to specify additional negative implementations; they exist only in the standard
113
+ library.
114
+
115
+ Auto traits may be added as an additional bound to any [ trait object] , even
116
+ though normally only one trait is allowed. For instance, `Box<dyn Debug + Send +
117
+ UnwindSafe>` is a valid type.
105
118
106
119
## ` Sized `
107
120
0 commit comments