Skip to content

Commit 85def30

Browse files
committed
shared_from_iter: Polish internal docs.
1 parent 8bbf1ab commit 85def30

File tree

3 files changed

+33
-30
lines changed

3 files changed

+33
-30
lines changed

src/liballoc/rc.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,11 @@ impl Rc<dyn Any> {
699699
}
700700

701701
impl<T: ?Sized> Rc<T> {
702-
// Allocates an `RcBox<T>` with sufficient space for
703-
// an unsized value where the value has the layout provided.
704-
//
705-
// The function `mem_to_rcbox` is called with the data pointer
706-
// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
702+
/// Allocates an `RcBox<T>` with sufficient space for
703+
/// an unsized value where the value has the layout provided.
704+
///
705+
/// The function `mem_to_rcbox` is called with the data pointer
706+
/// and must return back a (potentially fat)-pointer for the `RcBox<T>`.
707707
unsafe fn allocate_for_unsized(
708708
value_layout: Layout,
709709
mem_to_rcbox: impl FnOnce(*mut u8) -> *mut RcBox<T>
@@ -730,7 +730,7 @@ impl<T: ?Sized> Rc<T> {
730730
inner
731731
}
732732

733-
// Allocates an `RcBox<T>` with sufficient space for an unsized value
733+
/// Allocates an `RcBox<T>` with sufficient space for an unsized value
734734
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut RcBox<T> {
735735
// Allocate for the `RcBox<T>` using the given value.
736736
Self::allocate_for_unsized(
@@ -762,7 +762,7 @@ impl<T: ?Sized> Rc<T> {
762762
}
763763

764764
impl<T> Rc<[T]> {
765-
// Allocates an `RcBox<[T]>` with the given length.
765+
/// Allocates an `RcBox<[T]>` with the given length.
766766
unsafe fn allocate_for_slice(len: usize) -> *mut RcBox<[T]> {
767767
Self::allocate_for_unsized(
768768
Layout::array::<T>(len).unwrap(),
@@ -771,19 +771,19 @@ impl<T> Rc<[T]> {
771771
}
772772
}
773773

774-
// Sets the data pointer of a `?Sized` raw pointer.
775-
//
776-
// For a slice/trait object, this sets the `data` field and leaves the rest
777-
// unchanged. For a sized raw pointer, this simply sets the pointer.
774+
/// Sets the data pointer of a `?Sized` raw pointer.
775+
///
776+
/// For a slice/trait object, this sets the `data` field and leaves the rest
777+
/// unchanged. For a sized raw pointer, this simply sets the pointer.
778778
unsafe fn set_data_ptr<T: ?Sized, U>(mut ptr: *mut T, data: *mut U) -> *mut T {
779779
ptr::write(&mut ptr as *mut _ as *mut *mut u8, data as *mut u8);
780780
ptr
781781
}
782782

783783
impl<T> Rc<[T]> {
784-
// Copy elements from slice into newly allocated Rc<[T]>
785-
//
786-
// Unsafe because the caller must either take ownership or bind `T: Copy`
784+
/// Copy elements from slice into newly allocated Rc<[T]>
785+
///
786+
/// Unsafe because the caller must either take ownership or bind `T: Copy`
787787
unsafe fn copy_from_slice(v: &[T]) -> Rc<[T]> {
788788
let ptr = Self::allocate_for_slice(v.len());
789789

@@ -847,6 +847,7 @@ impl<T> Rc<[T]> {
847847
}
848848
}
849849

850+
/// Specialization trait used for `From<&[T]>`.
850851
trait RcFromSlice<T> {
851852
fn from_slice(slice: &[T]) -> Self;
852853
}

src/liballoc/sync.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,11 @@ impl<T: ?Sized> Arc<T> {
588588
}
589589

590590
impl<T: ?Sized> Arc<T> {
591-
// Allocates an `ArcInner<T>` with sufficient space for
592-
// an unsized value where the value has the layout provided.
593-
//
594-
// The function `mem_to_arcinner` is called with the data pointer
595-
// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
591+
/// Allocates an `ArcInner<T>` with sufficient space for
592+
/// an unsized value where the value has the layout provided.
593+
///
594+
/// The function `mem_to_arcinner` is called with the data pointer
595+
/// and must return back a (potentially fat)-pointer for the `ArcInner<T>`.
596596
unsafe fn allocate_for_unsized(
597597
value_layout: Layout,
598598
mem_to_arcinner: impl FnOnce(*mut u8) -> *mut ArcInner<T>
@@ -618,7 +618,7 @@ impl<T: ?Sized> Arc<T> {
618618
inner
619619
}
620620

621-
// Allocates an `ArcInner<T>` with sufficient space for an unsized value
621+
/// Allocates an `ArcInner<T>` with sufficient space for an unsized value.
622622
unsafe fn allocate_for_ptr(ptr: *const T) -> *mut ArcInner<T> {
623623
// Allocate for the `ArcInner<T>` using the given value.
624624
Self::allocate_for_unsized(
@@ -650,7 +650,7 @@ impl<T: ?Sized> Arc<T> {
650650
}
651651

652652
impl<T> Arc<[T]> {
653-
// Allocates an `ArcInner<[T]>` with the given length.
653+
/// Allocates an `ArcInner<[T]>` with the given length.
654654
unsafe fn allocate_for_slice(len: usize) -> *mut ArcInner<[T]> {
655655
Self::allocate_for_unsized(
656656
Layout::array::<T>(len).unwrap(),
@@ -659,19 +659,19 @@ impl<T> Arc<[T]> {
659659
}
660660
}
661661

662-
// Sets the data pointer of a `?Sized` raw pointer.
663-
//
664-
// For a slice/trait object, this sets the `data` field and leaves the rest
665-
// unchanged. For a sized raw pointer, this simply sets the pointer.
662+
/// Sets the data pointer of a `?Sized` raw pointer.
663+
///
664+
/// For a slice/trait object, this sets the `data` field and leaves the rest
665+
/// unchanged. For a sized raw pointer, this simply sets the pointer.
666666
unsafe fn set_data_ptr<T: ?Sized, U>(mut ptr: *mut T, data: *mut U) -> *mut T {
667667
ptr::write(&mut ptr as *mut _ as *mut *mut u8, data as *mut u8);
668668
ptr
669669
}
670670

671671
impl<T> Arc<[T]> {
672-
// Copy elements from slice into newly allocated Arc<[T]>
673-
//
674-
// Unsafe because the caller must either take ownership or bind `T: Copy`
672+
/// Copy elements from slice into newly allocated Arc<[T]>
673+
///
674+
/// Unsafe because the caller must either take ownership or bind `T: Copy`.
675675
unsafe fn copy_from_slice(v: &[T]) -> Arc<[T]> {
676676
let ptr = Self::allocate_for_slice(v.len());
677677

@@ -735,7 +735,7 @@ impl<T> Arc<[T]> {
735735
}
736736
}
737737

738-
// Specialization trait used for From<&[T]>
738+
/// Specialization trait used for `From<&[T]>`.
739739
trait ArcFromSlice<T> {
740740
fn from_slice(slice: &[T]) -> Self;
741741
}
@@ -1903,7 +1903,7 @@ impl<T, I: iter::TrustedLen<Item = T>> ArcFromIter<T, I> for Arc<[T]> {
19031903

19041904
impl<'a, T: 'a + Clone> ArcFromIter<&'a T, slice::Iter<'a, T>> for Arc<[T]> {
19051905
fn from_iter(iter: slice::Iter<'a, T>) -> Self {
1906-
// Delegate to `impl<T: Clone> From<&[T]> for Rc<[T]>`.
1906+
// Delegate to `impl<T: Clone> From<&[T]> for Arc<[T]>`.
19071907
//
19081908
// In the case that `T: Copy`, we get to use `ptr::copy_nonoverlapping`
19091909
// which is even more performant.

src/liballoc/tests/arc.rs

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ fn eq() {
8888
assert_eq!(*x.0.borrow(), 0);
8989
}
9090

91+
// The test code below is identical to that in `rc.rs`.
92+
// For better maintainability we therefore define this type alias.
9193
type Rc<T> = Arc<T>;
9294

9395
const SHARED_ITER_MAX: u16 = 100;

0 commit comments

Comments
 (0)