@@ -67,18 +67,26 @@ fine: inlining that reference everywhere has the same behavior as computing a
67
67
new reference each time. In both cases, there exists exactly one instance of
68
68
the mutable memory that everything references.
69
69
70
- ### 3. ` Sync `
70
+ ### 3. ` Send `
71
71
72
- Finally, the same constant reference is actually shared across threads. This is
73
- very similar to multiple threads having a shared reference to the same ` static ` ,
74
- which is why ` static ` must be ` Sync ` . So it seems like we should reject
75
- non-` Sync ` types, conforming with the desugaring described above.
72
+ Finally, the same constant value is actually shared across threads. This is
73
+ very similar to sending the same value across threads, so it seems like we
74
+ should reject non-` Send ` types. For shared references, this means the pointee
75
+ type ought to be ` Sync ` . That is already required for ` static ` items, so this
76
+ is consistent with the desugaring described above.
76
77
77
78
However, this does not currently happen, and there are several crates across the
78
79
ecosystem that would break if we just started enforcing this now. See
79
80
[ this issue] ( https://github.com/rust-lang/rust/issues/49206 ) and the
80
81
[ PR attempting to fix this] ( https://github.com/rust-lang/rust/pull/54424/ ) .
81
82
83
+ Also, one could make the argument that the value does not have to be ` Send `
84
+ because it is not actually sent to other threads; instead, conceptually, each
85
+ thread re-does the same computation. But we know they will all come to the same
86
+ result. This works, except when we consider address identity: with references
87
+ in the ` const ` , all threads will get the same address, unlike in case of a
88
+ per-thread recomputation which would lead to different addresses.
89
+
82
90
* Dynamic check.* It is unclear how the Miri engine could dynamically check this.
83
91
84
92
### 4. Drop
0 commit comments