@@ -8,31 +8,20 @@ cfg_if!(
88 } else {
99 #[ rustc_on_unimplemented(
1010 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`. \
1311 Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Send`"
1412 ) ]
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.
2216 pub unsafe auto trait DynSend { }
2317
2418 #[ rustc_on_unimplemented(
2519 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`. \
2820 Add it to `rustc_data_structures::marker` or use `IntoDyn` if it's already `Sync`"
2921 ) ]
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.
3625 pub unsafe auto trait DynSync { }
3726
3827 // Same with `Sync` and `Send`.
@@ -110,8 +99,8 @@ cfg_if!(
11099 [ thin_vec:: ThinVec <T > where T : DynSend ]
111100 [ smallvec:: SmallVec <A > where A : smallvec:: Array + DynSend ]
112101
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` .
115104 [ crate :: owning_ref:: OwningRef <O , T > where O : Send , T : ?Sized + Send ]
116105 [ crate :: owning_ref:: OwningRefMut <O , T > where O : Send , T : ?Sized + Send ]
117106 ) ;
@@ -196,8 +185,8 @@ cfg_if!(
196185 [ smallvec:: SmallVec <A > where A : smallvec:: Array + DynSync ]
197186 [ thin_vec:: ThinVec <T > where T : DynSync ]
198187
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` .
201190 [ crate :: owning_ref:: OwningRef <O , T > where O : Sync , T : ?Sized + Sync ]
202191 [ crate :: owning_ref:: OwningRefMut <O , T > where O : Sync , T : ?Sized + Sync ]
203192 ) ;
@@ -213,11 +202,11 @@ pub fn assert_dyn_send_sync_val<T: ?Sized + DynSync + DynSend>(_t: &T) {}
213202pub struct FromDyn < T > ( T ) ;
214203
215204impl < 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.
219205 #[ inline( always) ]
220206 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.
221210 #[ cfg( parallel_compiler) ]
222211 assert ! ( crate :: sync:: active( ) ) ;
223212 FromDyn ( val)
@@ -229,11 +218,11 @@ impl<T> FromDyn<T> {
229218 }
230219}
231220
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 .
233222#[ cfg( parallel_compiler) ]
234223unsafe impl < T : DynSend > Send for FromDyn < T > { }
235224
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 .
237226#[ cfg( parallel_compiler) ]
238227unsafe impl < T : DynSync > Sync for FromDyn < T > { }
239228
0 commit comments