Skip to content

Commit d1b4992

Browse files
committed
Replace parameter name dst with dest.
This avoids confusion between “DeSTination” and “Dynamically-Sized Type”.
1 parent 76b565f commit d1b4992

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

library/core/src/clone.rs

+22-22
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
225225
/// # Safety
226226
///
227227
/// Implementations must ensure that when `.clone_to_uninit()` returns normally rather than
228-
/// panicking, it always leaves `*dst` initialized as a valid value of type `Self`.
228+
/// panicking, it always leaves `*dest` initialized as a valid value of type `Self`.
229229
///
230230
/// # Examples
231231
///
@@ -280,7 +280,7 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
280280
/// }
281281
///
282282
/// unsafe impl<T: ?Sized + CloneToUninit> CloneToUninit for MyDst<T> {
283-
/// unsafe fn clone_to_uninit(&self, dst: *mut u8) {
283+
/// unsafe fn clone_to_uninit(&self, dest: *mut u8) {
284284
/// let offset_of_flag = offset_of!(Self, flag);
285285
/// // The offset of `self.contents` is dynamic because it depends on the alignment of T
286286
/// // which can be dynamic (if `T = dyn SomeTrait`). Therefore, we have to obtain it
@@ -293,13 +293,13 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
293293
/// // Since `flag` implements `Copy`, we can just copy it.
294294
/// // We use `pointer::write()` instead of assignment because the destination may be
295295
/// // uninitialized.
296-
/// dst.add(offset_of_flag).cast::<bool>().write(self.flag);
296+
/// dest.add(offset_of_flag).cast::<bool>().write(self.flag);
297297
///
298298
/// // Note: if `flag` owned any resources (i.e. had a `Drop` implementation), then we
299299
/// // must prepare to drop it in case `self.contents.clone_to_uninit()` panics.
300300
/// // In this simple case, where we have exactly one field for which `mem::needs_drop()`
301301
/// // might be true (`contents`), we don’t need to care about cleanup or ordering.
302-
/// self.contents.clone_to_uninit(dst.add(offset_of_contents));
302+
/// self.contents.clone_to_uninit(dest.add(offset_of_contents));
303303
///
304304
/// // All fields of the struct have been initialized, therefore the struct is initialized,
305305
/// // and we have satisfied our `unsafe impl CloneToUninit` obligations.
@@ -337,22 +337,22 @@ pub struct AssertParamIsCopy<T: Copy + ?Sized> {
337337
/// [trait object]: https://doc.rust-lang.org/reference/types/trait-object.html
338338
#[unstable(feature = "clone_to_uninit", issue = "126799")]
339339
pub unsafe trait CloneToUninit {
340-
/// Performs copy-assignment from `self` to `dst`.
340+
/// Performs copy-assignment from `self` to `dest`.
341341
///
342-
/// This is analogous to `std::ptr::write(dst.cast(), self.clone())`,
342+
/// This is analogous to `std::ptr::write(dest.cast(), self.clone())`,
343343
/// except that `Self` may be a dynamically-sized type ([`!Sized`](Sized)).
344344
///
345-
/// Before this function is called, `dst` may point to uninitialized memory.
346-
/// After this function is called, `dst` will point to initialized memory; it will be
345+
/// Before this function is called, `dest` may point to uninitialized memory.
346+
/// After this function is called, `dest` will point to initialized memory; it will be
347347
/// sound to create a `&Self` reference from the pointer with the [pointer metadata]
348348
/// from `self`.
349349
///
350350
/// # Safety
351351
///
352352
/// Behavior is undefined if any of the following conditions are violated:
353353
///
354-
/// * `dst` must be [valid] for writes for `std::mem::size_of_val(self)` bytes.
355-
/// * `dst` must be properly aligned to `std::mem::align_of_val(self)`.
354+
/// * `dest` must be [valid] for writes for `std::mem::size_of_val(self)` bytes.
355+
/// * `dest` must be properly aligned to `std::mem::align_of_val(self)`.
356356
///
357357
/// [valid]: crate::ptr#safety
358358
/// [pointer metadata]: crate::ptr::metadata()
@@ -361,60 +361,60 @@ pub unsafe trait CloneToUninit {
361361
///
362362
/// This function may panic. (For example, it might panic if memory allocation for a clone
363363
/// of a value owned by `self` fails.)
364-
/// If the call panics, then `*dst` should be treated as uninitialized memory; it must not be
364+
/// If the call panics, then `*dest` should be treated as uninitialized memory; it must not be
365365
/// read or dropped, because even if it was previously valid, it may have been partially
366366
/// overwritten.
367367
///
368-
/// The caller may also need to take care to deallocate the allocation pointed to by `dst`,
368+
/// The caller may also need to take care to deallocate the allocation pointed to by `dest`,
369369
/// if applicable, to avoid a memory leak, and may need to take other precautions to ensure
370370
/// soundness in the presence of unwinding.
371371
///
372372
/// Implementors should avoid leaking values by, upon unwinding, dropping all component values
373373
/// that might have already been created. (For example, if a `[Foo]` of length 3 is being
374374
/// cloned, and the second of the three calls to `Foo::clone()` unwinds, then the first `Foo`
375375
/// cloned should be dropped.)
376-
unsafe fn clone_to_uninit(&self, dst: *mut u8);
376+
unsafe fn clone_to_uninit(&self, dest: *mut u8);
377377
}
378378

379379
#[unstable(feature = "clone_to_uninit", issue = "126799")]
380380
unsafe impl<T: Clone> CloneToUninit for T {
381381
#[inline]
382-
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
382+
unsafe fn clone_to_uninit(&self, dest: *mut u8) {
383383
// SAFETY: we're calling a specialization with the same contract
384-
unsafe { <T as self::uninit::CopySpec>::clone_one(self, dst.cast::<T>()) }
384+
unsafe { <T as self::uninit::CopySpec>::clone_one(self, dest.cast::<T>()) }
385385
}
386386
}
387387

388388
#[unstable(feature = "clone_to_uninit", issue = "126799")]
389389
unsafe impl<T: Clone> CloneToUninit for [T] {
390390
#[inline]
391391
#[cfg_attr(debug_assertions, track_caller)]
392-
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
393-
let dst: *mut [T] = dst.with_metadata_of(self);
392+
unsafe fn clone_to_uninit(&self, dest: *mut u8) {
393+
let dest: *mut [T] = dest.with_metadata_of(self);
394394
// SAFETY: we're calling a specialization with the same contract
395-
unsafe { <T as self::uninit::CopySpec>::clone_slice(self, dst) }
395+
unsafe { <T as self::uninit::CopySpec>::clone_slice(self, dest) }
396396
}
397397
}
398398

399399
#[unstable(feature = "clone_to_uninit", issue = "126799")]
400400
unsafe impl CloneToUninit for str {
401401
#[inline]
402402
#[cfg_attr(debug_assertions, track_caller)]
403-
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
403+
unsafe fn clone_to_uninit(&self, dest: *mut u8) {
404404
// SAFETY: str is just a [u8] with UTF-8 invariant
405-
unsafe { self.as_bytes().clone_to_uninit(dst) }
405+
unsafe { self.as_bytes().clone_to_uninit(dest) }
406406
}
407407
}
408408

409409
#[unstable(feature = "clone_to_uninit", issue = "126799")]
410410
unsafe impl CloneToUninit for crate::ffi::CStr {
411411
#[cfg_attr(debug_assertions, track_caller)]
412-
unsafe fn clone_to_uninit(&self, dst: *mut u8) {
412+
unsafe fn clone_to_uninit(&self, dest: *mut u8) {
413413
// SAFETY: For now, CStr is just a #[repr(trasnsparent)] [c_char] with some invariants.
414414
// And we can cast [c_char] to [u8] on all supported platforms (see: to_bytes_with_nul).
415415
// The pointer metadata properly preserves the length (so NUL is also copied).
416416
// See: `cstr_metadata_is_length_with_nul` in tests.
417-
unsafe { self.to_bytes_with_nul().clone_to_uninit(dst) }
417+
unsafe { self.to_bytes_with_nul().clone_to_uninit(dest) }
418418
}
419419
}
420420

0 commit comments

Comments
 (0)