Skip to content

Commit 164929d

Browse files
Rollup merge of #163063 - Ddystopia:borrowed-cursor-send-sync, r=clarfonthey
Restore `Send` and `Sync` for `BorrowedCursor` In #160563 `Send` and `Sync` was accidentally [removed] from `BorrowedCursor`, now they're added back. This is fine because they're used equivalently to `&mut T`. [removed]: #160563 (comment)
2 parents c81d09c + 428aeee commit 164929d

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎library/core/src/io/borrowed_buf.rs‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ pub struct BorrowedCursor<'a, T> {
222222
borrowed_buf: NonNull<BorrowedBuf<'a, T>>,
223223
}
224224

225+
// SAFETY: A `BorrowedCursor<'a, T>` is a unique borrow of a `BorrowedBuf<'a, T>`, which is a
226+
// `&'a mut [MaybeUninit<T>]` and two `Copy` fields. The `buf` raw pointer is used like
227+
// `&mut [MaybeUninit<T>]` so `T: Send` -> `Send` and is: `T: Sync` -> `Sync`, and the
228+
// `borrowed_buf` only touches two `Copy` fields, without depending of `T`.
229+
unsafe impl<T: Send> Send for BorrowedCursor<'_, T> {}
230+
// SAFETY: See the `Send` impl above.
231+
unsafe impl<T: Sync> Sync for BorrowedCursor<'_, T> {}
232+
225233
impl<T> Debug for BorrowedCursor<'_, T> {
226234
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
227235
let buf = BorrowedBufDebug {

0 commit comments

Comments
 (0)