Skip to content

Commit 34555f1

Browse files
committed
core: Remove BorrowedCursor::uninit_mut
I assume that this method was there for completeness, but there is hardly any useful use of it: the buffer it gave was not always connected to the start of the cursor and its use required `unsafe` anyway to mark the bytes as initialized.
1 parent 803b4d2 commit 34555f1

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,15 +237,6 @@ impl<'a> BorrowedCursor<'a> {
237237
}
238238
}
239239

240-
/// Returns a mutable reference to the uninitialized part of the cursor.
241-
///
242-
/// It is safe to uninitialize any of these bytes.
243-
#[inline]
244-
pub fn uninit_mut(&mut self) -> &mut [MaybeUninit<u8>] {
245-
// SAFETY: always in bounds
246-
unsafe { self.buf.buf.get_unchecked_mut(self.buf.init..) }
247-
}
248-
249240
/// Returns a mutable reference to the whole cursor.
250241
///
251242
/// # Safety
@@ -298,7 +289,9 @@ impl<'a> BorrowedCursor<'a> {
298289
/// Initializes all bytes in the cursor.
299290
#[inline]
300291
pub fn ensure_init(&mut self) -> &mut Self {
301-
let uninit = self.uninit_mut();
292+
// SAFETY: always in bounds and we never uninitialize these bytes.
293+
let uninit = unsafe { self.buf.buf.get_unchecked_mut(self.buf.init..) };
294+
302295
// SAFETY: 0 is a valid value for MaybeUninit<u8> and the length matches the allocation
303296
// since it is comes from a slice reference.
304297
unsafe {

library/coretests/tests/io/borrowed_buf.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ fn cursor_set_init() {
143143

144144
assert_eq!(rbuf.init_len(), 8);
145145
assert_eq!(rbuf.unfilled().init_mut().len(), 8);
146-
assert_eq!(rbuf.unfilled().uninit_mut().len(), 8);
147146
assert_eq!(unsafe { rbuf.unfilled().as_mut().len() }, 16);
148147

149148
rbuf.unfilled().advance(4);
@@ -160,6 +159,5 @@ fn cursor_set_init() {
160159

161160
assert_eq!(rbuf.init_len(), 12);
162161
assert_eq!(rbuf.unfilled().init_mut().len(), 8);
163-
assert_eq!(rbuf.unfilled().uninit_mut().len(), 4);
164162
assert_eq!(unsafe { rbuf.unfilled().as_mut().len() }, 12);
165163
}

0 commit comments

Comments
 (0)