@@ -8,31 +8,20 @@ cfg_if!(
8
8
} else {
9
9
#[ rustc_on_unimplemented(
10
10
message = "`{Self}` doesn't implement `DynSend`. \
11
- Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Send`",
12
- label = "`{Self}` doesn't implement `DynSend`. \
13
11
Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Send`"
14
12
) ]
15
- // Ensure data structures is `Send` if `sync::active()` is true.
16
- // `sync::active()` should be checked before using these data structures.
17
- // Note: Ensure that the data structure **will not break**
18
- // thread safety after being created.
19
- //
20
- // `sync::active()` should be checked when downcasting these data structures
21
- // to `Send` via `FromDyn`.
13
+ // This is an auto trait for types which can be sent across threads if `sync::active()`
14
+ // is true. These types can be wrapped in a `FromDyn` to get a `Send` type. Wrapping a
15
+ // `Send` type in `IntoDyn` will create a `DynSend` type.
22
16
pub unsafe auto trait DynSend { }
23
17
24
18
#[ rustc_on_unimplemented(
25
19
message = "`{Self}` doesn't implement `DynSync`. \
26
- Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Sync`",
27
- label = "`{Self}` doesn't implement `DynSync`. \
28
20
Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Sync`"
29
21
) ]
30
- // Ensure data structures is `Sync` if `sync::active()` is true.
31
- // Note: Ensure that the data structure **will not break**
32
- // thread safety after being checked.
33
- //
34
- // `sync::active()` should be checked when downcasting these data structures
35
- // to `Send` via `FromDyn`.
22
+ // This is an auto trait for types which can be shared across threads if `sync::active()`
23
+ // is true. These types can be wrapped in a `FromDyn` to get a `Sync` type. Wrapping a
24
+ // `Sync` type in `IntoDyn` will create a `DynSync` type.
36
25
pub unsafe auto trait DynSync { }
37
26
38
27
// Same with `Sync` and `Send`.
@@ -110,8 +99,8 @@ cfg_if!(
110
99
[ thin_vec:: ThinVec <T > where T : DynSend ]
111
100
[ smallvec:: SmallVec <A > where A : smallvec:: Array + DynSend ]
112
101
113
- // We use `Send` here to omit some extra code , since they are only
114
- // used in `Send` situations now .
102
+ // We use `Send` here, since they are only used in `Send` situations now.
103
+ // In this case we don't need copy or change the codes in `crate::owning_ref` .
115
104
[ crate :: owning_ref:: OwningRef <O , T > where O : Send , T : ?Sized + Send ]
116
105
[ crate :: owning_ref:: OwningRefMut <O , T > where O : Send , T : ?Sized + Send ]
117
106
) ;
@@ -196,8 +185,8 @@ cfg_if!(
196
185
[ smallvec:: SmallVec <A > where A : smallvec:: Array + DynSync ]
197
186
[ thin_vec:: ThinVec <T > where T : DynSync ]
198
187
199
- // We use `Sync` here to omit some extra code , since they are only
200
- // used in `Sync` situations now .
188
+ // We use `Sync` here, since they are only used in `Sync` situations now.
189
+ // In this case we don't need copy or change the codes in `crate::owning_ref` .
201
190
[ crate :: owning_ref:: OwningRef <O , T > where O : Sync , T : ?Sized + Sync ]
202
191
[ crate :: owning_ref:: OwningRefMut <O , T > where O : Sync , T : ?Sized + Sync ]
203
192
) ;
@@ -213,11 +202,11 @@ pub fn assert_dyn_send_sync_val<T: ?Sized + DynSync + DynSend>(_t: &T) {}
213
202
pub struct FromDyn < T > ( T ) ;
214
203
215
204
impl < T > FromDyn < T > {
216
- // Check `sync::active()` when creating this structure
217
- // and downcasting to `Send`. So we can ensure it is
218
- // thread-safe.
219
205
#[ inline( always) ]
220
206
pub fn from ( val : T ) -> Self {
207
+ // Check that `sync::active()` is true on creation so we can
208
+ // implement `Send` and `Sync` for this structure when `T`
209
+ // implements `DynSend` and `DynSync` respectively.
221
210
#[ cfg( parallel_compiler) ]
222
211
assert ! ( crate :: sync:: active( ) ) ;
223
212
FromDyn ( val)
@@ -229,11 +218,11 @@ impl<T> FromDyn<T> {
229
218
}
230
219
}
231
220
232
- // `FromDyn` is `Send` if `T` is `DynSend`, since it check when created .
221
+ // `FromDyn` is `Send` if `T` is `DynSend`, since it ensures that sync::active() is true .
233
222
#[ cfg( parallel_compiler) ]
234
223
unsafe impl < T : DynSend > Send for FromDyn < T > { }
235
224
236
- // `FromDyn` is `Sync` if `T` is `DynSync`, since it check when created .
225
+ // `FromDyn` is `Sync` if `T` is `DynSync`, since it ensures that sync::active() is true .
237
226
#[ cfg( parallel_compiler) ]
238
227
unsafe impl < T : DynSync > Sync for FromDyn < T > { }
239
228
0 commit comments