summaryrefslogtreecommitdiffstats
path: root/vendor/syn/src/thread.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /vendor/syn/src/thread.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/src/thread.rs')
-rw-r--r--vendor/syn/src/thread.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/vendor/syn/src/thread.rs b/vendor/syn/src/thread.rs
index 63fdea834..b33d248af 100644
--- a/vendor/syn/src/thread.rs
+++ b/vendor/syn/src/thread.rs
@@ -12,6 +12,9 @@ pub(crate) struct ThreadBound<T> {
unsafe impl<T> Sync for ThreadBound<T> {}
// Send bound requires Copy, as otherwise Drop could run in the wrong place.
+//
+// Today Copy and Drop are mutually exclusive so `T: Copy` implies `T: !Drop`.
+// This impl needs to be revisited if that restriction is relaxed in the future.
unsafe impl<T: Copy> Send for ThreadBound<T> {}
impl<T> ThreadBound<T> {
@@ -40,11 +43,18 @@ impl<T: Debug> Debug for ThreadBound<T> {
}
}
-impl<T: Clone> Clone for ThreadBound<T> {
+// Copy the bytes of T, even if the currently running thread is the "wrong"
+// thread. This is fine as long as the original thread is not simultaneously
+// mutating this value via interior mutability, which would be a data race.
+//
+// Currently `T: Copy` is sufficient to guarantee that T contains no interior
+// mutability, because _all_ interior mutability in Rust is built on
+// std::cell::UnsafeCell, which has no Copy impl. This impl needs to be
+// revisited if that restriction is relaxed in the future.
+impl<T: Copy> Copy for ThreadBound<T> {}
+
+impl<T: Copy> Clone for ThreadBound<T> {
fn clone(&self) -> Self {
- ThreadBound {
- value: self.value.clone(),
- thread_id: self.thread_id,
- }
+ *self
}
}