Skip to content

Commit 009a5d1

Browse files
committed
Rename BorrowedCursor::advance_unchecked to advance
1 parent 71db628 commit 009a5d1

File tree

15 files changed

+22
-22
lines changed

15 files changed

+22
-22
lines changed

library/core/src/io/borrowed_buf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl<'a> BorrowedCursor<'a> {
272272
/// Panics if there are less than `n` bytes initialized.
273273
#[unstable(feature = "borrowed_buf_init", issue = "78485")]
274274
#[inline]
275-
pub fn advance(&mut self, n: usize) -> &mut Self {
275+
pub fn advance_checked(&mut self, n: usize) -> &mut Self {
276276
// The substraction cannot underflow by invariant of this type.
277277
let init_unfilled = if self.buf.init { self.buf.buf.len() - self.buf.filled } else { 0 };
278278
assert!(n <= init_unfilled);
@@ -292,7 +292,7 @@ impl<'a> BorrowedCursor<'a> {
292292
/// The caller must ensure that the first `n` bytes of the cursor have been properly
293293
/// initialised.
294294
#[inline]
295-
pub unsafe fn advance_unchecked(&mut self, n: usize) -> &mut Self {
295+
pub unsafe fn advance(&mut self, n: usize) -> &mut Self {
296296
self.buf.filled += n;
297297
self
298298
}

library/coretests/tests/io/borrowed_buf.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn advance_filled() {
4040
let buf: &mut [_] = &mut [0; 16];
4141
let mut rbuf: BorrowedBuf<'_> = buf.into();
4242

43-
rbuf.unfilled().advance(1);
43+
rbuf.unfilled().advance_checked(1);
4444

4545
assert_eq!(rbuf.filled().len(), 1);
4646
assert_eq!(rbuf.unfilled().capacity(), 15);
@@ -51,7 +51,7 @@ fn clear() {
5151
let buf: &mut [_] = &mut [255; 16];
5252
let mut rbuf: BorrowedBuf<'_> = buf.into();
5353

54-
rbuf.unfilled().advance(16);
54+
rbuf.unfilled().advance_checked(16);
5555

5656
assert_eq!(rbuf.filled().len(), 16);
5757
assert_eq!(rbuf.unfilled().capacity(), 0);
@@ -131,7 +131,7 @@ fn cursor_set_init() {
131131
assert!(cursor.is_init());
132132
assert_eq!(unsafe { cursor.as_mut().len() }, 16);
133133

134-
cursor.advance(4);
134+
cursor.advance_checked(4);
135135

136136
assert_eq!(unsafe { cursor.as_mut().len() }, 12);
137137

@@ -157,7 +157,7 @@ fn cursor_with_unfilled_buf() {
157157
assert!(!buf.is_init());
158158

159159
buf.unfilled().ensure_init();
160-
buf.unfilled().advance(4);
160+
buf.unfilled().advance_checked(4);
161161
});
162162

163163
assert!(cursor.is_init());

library/std/src/io/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ where
570570
F: FnOnce(&mut [u8]) -> Result<usize>,
571571
{
572572
let n = read(cursor.ensure_init())?;
573-
cursor.advance(n);
573+
cursor.advance_checked(n);
574574
Ok(())
575575
}
576576

@@ -3113,7 +3113,7 @@ impl<T: Read> Read for Take<T> {
31133113

31143114
unsafe {
31153115
// SAFETY: filled bytes have been filled
3116-
buf.advance_unchecked(filled);
3116+
buf.advance(filled);
31173117
}
31183118

31193119
self.limit -= filled as u64;

library/std/src/io/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ impl Read for Repeat {
283283
// SAFETY: No uninit bytes are being written.
284284
unsafe { buf.as_mut() }.write_filled(self.byte);
285285
// SAFETY: the entire unfilled portion of buf has been initialized.
286-
unsafe { buf.advance_unchecked(buf.capacity()) };
286+
unsafe { buf.advance(buf.capacity()) };
287287
Ok(())
288288
}
289289

library/std/src/sys/fd/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl FileDesc {
3333
)
3434
})?;
3535
// SAFETY: Exactly `result` bytes have been filled.
36-
unsafe { buf.advance_unchecked(result as usize) };
36+
unsafe { buf.advance(result as usize) };
3737
Ok(())
3838
}
3939

library/std/src/sys/fd/unix.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ impl FileDesc {
185185

186186
// SAFETY: `ret` bytes were written to the initialized portion of the buffer
187187
unsafe {
188-
cursor.advance_unchecked(ret as usize);
188+
cursor.advance(ret as usize);
189189
}
190190
Ok(())
191191
}
@@ -203,7 +203,7 @@ impl FileDesc {
203203

204204
// SAFETY: `ret` bytes were written to the initialized portion of the buffer
205205
unsafe {
206-
cursor.advance_unchecked(ret as usize);
206+
cursor.advance(ret as usize);
207207
}
208208
Ok(())
209209
}

library/std/src/sys/fs/solid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl File {
401401

402402
// Safety: `num_bytes_read` bytes were written to the unfilled
403403
// portion of the buffer
404-
cursor.advance_unchecked(num_bytes_read);
404+
cursor.advance(num_bytes_read);
405405

406406
Ok(())
407407
}

library/std/src/sys/net/connection/socket/hermit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl Socket {
143143
)
144144
})?;
145145
unsafe {
146-
buf.advance_unchecked(ret as usize);
146+
buf.advance(ret as usize);
147147
}
148148
Ok(())
149149
}

library/std/src/sys/net/connection/socket/solid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ impl Socket {
190190
netc::recv(self.as_raw_fd(), buf.as_mut().as_mut_ptr().cast(), buf.capacity(), flags)
191191
})?;
192192
unsafe {
193-
buf.advance_unchecked(ret as usize);
193+
buf.advance(ret as usize);
194194
}
195195
Ok(())
196196
}

library/std/src/sys/net/connection/socket/unix.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ impl Socket {
294294
)
295295
})?;
296296
unsafe {
297-
buf.advance_unchecked(ret as usize);
297+
buf.advance(ret as usize);
298298
}
299299
Ok(())
300300
}

0 commit comments

Comments
 (0)