Skip to content

Commit f94f928

Browse files
committed
Fix doc nits
Many tiny changes to stdlib doc comments to make them consistent (for example "Returns foo", rather than "Return foo"), adding missing periods, paragraph breaks, backticks for monospace style, and other minor nits.
1 parent adeb79d commit f94f928

File tree

147 files changed

+810
-740
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+810
-740
lines changed

library/alloc/src/alloc.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pub struct Global;
5757
#[cfg(test)]
5858
pub use std::alloc::Global;
5959

60-
/// Allocate memory with the global allocator.
60+
/// Allocates memory with the global allocator.
6161
///
6262
/// This function forwards calls to the [`GlobalAlloc::alloc`] method
6363
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -101,7 +101,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
101101
}
102102
}
103103

104-
/// Deallocate memory with the global allocator.
104+
/// Deallocates memory with the global allocator.
105105
///
106106
/// This function forwards calls to the [`GlobalAlloc::dealloc`] method
107107
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -119,7 +119,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
119119
unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
120120
}
121121

122-
/// Reallocate memory with the global allocator.
122+
/// Reallocates memory with the global allocator.
123123
///
124124
/// This function forwards calls to the [`GlobalAlloc::realloc`] method
125125
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -138,7 +138,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
138138
unsafe { __rust_realloc(ptr, layout.size(), layout.align(), new_size) }
139139
}
140140

141-
/// Allocate zero-initialized memory with the global allocator.
141+
/// Allocates zero-initialized memory with the global allocator.
142142
///
143143
/// This function forwards calls to the [`GlobalAlloc::alloc_zeroed`] method
144144
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -345,7 +345,7 @@ extern "Rust" {
345345
fn __rust_alloc_error_handler(size: usize, align: usize) -> !;
346346
}
347347

348-
/// Signal a memory allocation error.
348+
/// Signals a memory allocation error.
349349
///
350350
/// Callers of memory allocation APIs wishing to cease execution
351351
/// in response to an allocation error are encouraged to call this function,

library/alloc/src/boxed.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -1189,9 +1189,11 @@ impl<T: ?Sized, A: Allocator> Box<T, A> {
11891189
}
11901190

11911191
/// Consumes and leaks the `Box`, returning a mutable reference,
1192-
/// `&'a mut T`. Note that the type `T` must outlive the chosen lifetime
1193-
/// `'a`. If the type has only static references, or none at all, then this
1194-
/// may be chosen to be `'static`.
1192+
/// `&'a mut T`.
1193+
///
1194+
/// Note that the type `T` must outlive the chosen lifetime `'a`. If the type
1195+
/// has only static references, or none at all, then this may be chosen to be
1196+
/// `'static`.
11951197
///
11961198
/// This function is mainly useful for data that lives for the remainder of
11971199
/// the program's life. Dropping the returned reference will cause a memory
@@ -1774,7 +1776,7 @@ impl<T, const N: usize> TryFrom<Vec<T>> for Box<[T; N]> {
17741776
}
17751777

17761778
impl<A: Allocator> Box<dyn Any, A> {
1777-
/// Attempt to downcast the box to a concrete type.
1779+
/// Attempts to downcast the box to a concrete type.
17781780
///
17791781
/// # Examples
17801782
///
@@ -1833,7 +1835,7 @@ impl<A: Allocator> Box<dyn Any, A> {
18331835
}
18341836

18351837
impl<A: Allocator> Box<dyn Any + Send, A> {
1836-
/// Attempt to downcast the box to a concrete type.
1838+
/// Attempts to downcast the box to a concrete type.
18371839
///
18381840
/// # Examples
18391841
///
@@ -1892,7 +1894,7 @@ impl<A: Allocator> Box<dyn Any + Send, A> {
18921894
}
18931895

18941896
impl<A: Allocator> Box<dyn Any + Send + Sync, A> {
1895-
/// Attempt to downcast the box to a concrete type.
1897+
/// Attempts to downcast the box to a concrete type.
18961898
///
18971899
/// # Examples
18981900
///

library/alloc/src/collections/binary_heap/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,7 @@ impl<T, A: Allocator> BinaryHeap<T, A> {
965965
}
966966

967967
/// Returns an iterator which retrieves elements in heap order.
968+
///
968969
/// This method consumes the original heap.
969970
///
970971
/// # Examples
@@ -1361,7 +1362,7 @@ struct Hole<'a, T: 'a> {
13611362
}
13621363

13631364
impl<'a, T> Hole<'a, T> {
1364-
/// Create a new `Hole` at index `pos`.
1365+
/// Creates a new `Hole` at index `pos`.
13651366
///
13661367
/// Unsafe because pos must be within the data slice.
13671368
#[inline]

library/alloc/src/collections/btree/map/entry.rs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ impl<'a, K: Ord, V, A: Allocator + Clone> Entry<'a, K, V, A> {
189189
}
190190

191191
/// Ensures a value is in the entry by inserting, if empty, the result of the default function.
192+
///
192193
/// This method allows for generating key-derived values for insertion by providing the default
193194
/// function a reference to the key that was moved during the `.entry(key)` method call.
194195
///

library/alloc/src/fmt.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ pub use core::fmt::{LowerHex, Pointer, UpperHex};
600600
#[cfg(not(no_global_oom_handling))]
601601
use crate::string;
602602

603-
/// The `format` function takes an [`Arguments`] struct and returns the resulting
604-
/// formatted string.
603+
/// Takes an [`Arguments`] struct and returns the resulting formatted string.
605604
///
606605
/// The [`Arguments`] instance can be created with the [`format_args!`] macro.
607606
///

library/alloc/src/raw_vec.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Cap {
5252
/// * Produces `Unique::dangling()` on zero-length allocations.
5353
/// * Avoids freeing `Unique::dangling()`.
5454
/// * Catches all overflows in capacity computations (promotes them to "capacity overflow" panics).
55-
/// * Guards against 32-bit systems allocating more than isize::MAX bytes.
55+
/// * Guards against 32-bit systems allocating more than `isize::MAX` bytes.
5656
/// * Guards against overflowing your length.
5757
/// * Calls `handle_alloc_error` for fallible allocations.
5858
/// * Contains a `ptr::Unique` and thus endows the user with all related benefits.
@@ -484,7 +484,7 @@ impl<T, A: Allocator> RawVec<T, A> {
484484

485485
// `finish_grow` is non-generic over `T`.
486486
let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
487-
// SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than isize::MAX items
487+
// SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
488488
unsafe { self.set_ptr_and_cap(ptr, cap) };
489489
Ok(())
490490
}
@@ -504,7 +504,7 @@ impl<T, A: Allocator> RawVec<T, A> {
504504

505505
// `finish_grow` is non-generic over `T`.
506506
let ptr = finish_grow(new_layout, self.current_memory(), &mut self.alloc)?;
507-
// SAFETY: finish_grow would have resulted in a capacity overflow if we tried to allocate more than isize::MAX items
507+
// SAFETY: `finish_grow` would have resulted in a capacity overflow if we tried to allocate more than `isize::MAX` items
508508
unsafe {
509509
self.set_ptr_and_cap(ptr, cap);
510510
}

library/alloc/src/rc.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<T> Rc<T> {
439439
/// }
440440
///
441441
/// impl Gadget {
442-
/// /// Construct a reference counted Gadget.
442+
/// /// Constructs a reference counted Gadget.
443443
/// fn new() -> Rc<Self> {
444444
/// // `me` is a `Weak<Gadget>` pointing at the new allocation of the
445445
/// // `Rc` we're constructing.
@@ -449,7 +449,7 @@ impl<T> Rc<T> {
449449
/// })
450450
/// }
451451
///
452-
/// /// Return a reference counted pointer to Self.
452+
/// /// Returns a reference counted pointer to Self.
453453
/// fn me(&self) -> Rc<Self> {
454454
/// self.me.upgrade().unwrap()
455455
/// }
@@ -1902,7 +1902,7 @@ impl<T: Clone, A: Allocator> Rc<T, A> {
19021902
}
19031903

19041904
impl<A: Allocator> Rc<dyn Any, A> {
1905-
/// Attempt to downcast the `Rc<dyn Any>` to a concrete type.
1905+
/// Attempts to downcast the `Rc<dyn Any>` to a concrete type.
19061906
///
19071907
/// # Examples
19081908
///
@@ -2588,7 +2588,7 @@ impl<T, const N: usize> From<[T; N]> for Rc<[T]> {
25882588
#[cfg(not(no_global_oom_handling))]
25892589
#[stable(feature = "shared_from_slice", since = "1.21.0")]
25902590
impl<T: Clone> From<&[T]> for Rc<[T]> {
2591-
/// Allocate a reference-counted slice and fill it by cloning `v`'s items.
2591+
/// Allocates a reference-counted slice and fills it by cloning `v`'s items.
25922592
///
25932593
/// # Example
25942594
///
@@ -2607,7 +2607,7 @@ impl<T: Clone> From<&[T]> for Rc<[T]> {
26072607
#[cfg(not(no_global_oom_handling))]
26082608
#[stable(feature = "shared_from_slice", since = "1.21.0")]
26092609
impl From<&str> for Rc<str> {
2610-
/// Allocate a reference-counted string slice and copy `v` into it.
2610+
/// Allocates a reference-counted string slice and copies `v` into it.
26112611
///
26122612
/// # Example
26132613
///
@@ -2626,7 +2626,7 @@ impl From<&str> for Rc<str> {
26262626
#[cfg(not(no_global_oom_handling))]
26272627
#[stable(feature = "shared_from_slice", since = "1.21.0")]
26282628
impl From<String> for Rc<str> {
2629-
/// Allocate a reference-counted string slice and copy `v` into it.
2629+
/// Allocates a reference-counted string slice and copies `v` into it.
26302630
///
26312631
/// # Example
26322632
///
@@ -2664,7 +2664,7 @@ impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Rc<T, A> {
26642664
#[cfg(not(no_global_oom_handling))]
26652665
#[stable(feature = "shared_from_slice", since = "1.21.0")]
26662666
impl<T, A: Allocator> From<Vec<T, A>> for Rc<[T], A> {
2667-
/// Allocate a reference-counted slice and move `v`'s items into it.
2667+
/// Allocates a reference-counted slice and moves `v`'s items into it.
26682668
///
26692669
/// # Example
26702670
///
@@ -2697,8 +2697,8 @@ where
26972697
B: ToOwned + ?Sized,
26982698
Rc<B>: From<&'a B> + From<B::Owned>,
26992699
{
2700-
/// Create a reference-counted pointer from
2701-
/// a clone-on-write pointer by copying its content.
2700+
/// Creates a reference-counted pointer from a clone-on-write pointer by
2701+
/// copying its content.
27022702
///
27032703
/// # Example
27042704
///
@@ -3530,7 +3530,7 @@ impl<T: ?Sized, A: Allocator> AsRef<T> for Rc<T, A> {
35303530
#[stable(feature = "pin", since = "1.33.0")]
35313531
impl<T: ?Sized, A: Allocator> Unpin for Rc<T, A> {}
35323532

3533-
/// Get the offset within an `RcBox` for the payload behind a pointer.
3533+
/// Gets the offset within an `RcBox` for the payload behind a pointer.
35343534
///
35353535
/// # Safety
35363536
///
@@ -3738,7 +3738,7 @@ struct UniqueRcUninit<T: ?Sized, A: Allocator> {
37383738

37393739
#[cfg(not(no_global_oom_handling))]
37403740
impl<T: ?Sized, A: Allocator> UniqueRcUninit<T, A> {
3741-
/// Allocate a RcBox with layout suitable to contain `for_value` or a clone of it.
3741+
/// Allocates a RcBox with layout suitable to contain `for_value` or a clone of it.
37423742
fn new(for_value: &T, alloc: A) -> UniqueRcUninit<T, A> {
37433743
let layout = Layout::for_value(for_value);
37443744
let ptr = unsafe {

library/alloc/src/sync.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ impl<T> Arc<T> {
428428
/// }
429429
///
430430
/// impl Gadget {
431-
/// /// Construct a reference counted Gadget.
431+
/// /// Constructs a reference counted Gadget.
432432
/// fn new() -> Arc<Self> {
433433
/// // `me` is a `Weak<Gadget>` pointing at the new allocation of the
434434
/// // `Arc` we're constructing.
@@ -438,7 +438,7 @@ impl<T> Arc<T> {
438438
/// })
439439
/// }
440440
///
441-
/// /// Return a reference counted pointer to Self.
441+
/// /// Returns a reference counted pointer to Self.
442442
/// fn me(&self) -> Arc<Self> {
443443
/// self.me.upgrade().unwrap()
444444
/// }
@@ -2534,7 +2534,7 @@ unsafe impl<#[may_dangle] T: ?Sized, A: Allocator> Drop for Arc<T, A> {
25342534
}
25352535

25362536
impl<A: Allocator> Arc<dyn Any + Send + Sync, A> {
2537-
/// Attempt to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
2537+
/// Attempts to downcast the `Arc<dyn Any + Send + Sync>` to a concrete type.
25382538
///
25392539
/// # Examples
25402540
///
@@ -3550,7 +3550,7 @@ impl<T, const N: usize> From<[T; N]> for Arc<[T]> {
35503550
#[cfg(not(no_global_oom_handling))]
35513551
#[stable(feature = "shared_from_slice", since = "1.21.0")]
35523552
impl<T: Clone> From<&[T]> for Arc<[T]> {
3553-
/// Allocate a reference-counted slice and fill it by cloning `v`'s items.
3553+
/// Allocates a reference-counted slice and fills it by cloning `v`'s items.
35543554
///
35553555
/// # Example
35563556
///
@@ -3569,7 +3569,7 @@ impl<T: Clone> From<&[T]> for Arc<[T]> {
35693569
#[cfg(not(no_global_oom_handling))]
35703570
#[stable(feature = "shared_from_slice", since = "1.21.0")]
35713571
impl From<&str> for Arc<str> {
3572-
/// Allocate a reference-counted `str` and copy `v` into it.
3572+
/// Allocates a reference-counted `str` and copies `v` into it.
35733573
///
35743574
/// # Example
35753575
///
@@ -3588,7 +3588,7 @@ impl From<&str> for Arc<str> {
35883588
#[cfg(not(no_global_oom_handling))]
35893589
#[stable(feature = "shared_from_slice", since = "1.21.0")]
35903590
impl From<String> for Arc<str> {
3591-
/// Allocate a reference-counted `str` and copy `v` into it.
3591+
/// Allocates a reference-counted `str` and copies `v` into it.
35923592
///
35933593
/// # Example
35943594
///
@@ -3626,7 +3626,7 @@ impl<T: ?Sized, A: Allocator> From<Box<T, A>> for Arc<T, A> {
36263626
#[cfg(not(no_global_oom_handling))]
36273627
#[stable(feature = "shared_from_slice", since = "1.21.0")]
36283628
impl<T, A: Allocator + Clone> From<Vec<T, A>> for Arc<[T], A> {
3629-
/// Allocate a reference-counted slice and move `v`'s items into it.
3629+
/// Allocates a reference-counted slice and moves `v`'s items into it.
36303630
///
36313631
/// # Example
36323632
///
@@ -3659,8 +3659,8 @@ where
36593659
B: ToOwned + ?Sized,
36603660
Arc<B>: From<&'a B> + From<B::Owned>,
36613661
{
3662-
/// Create an atomically reference-counted pointer from
3663-
/// a clone-on-write pointer by copying its content.
3662+
/// Creates an atomically reference-counted pointer from a clone-on-write
3663+
/// pointer by copying its content.
36643664
///
36653665
/// # Example
36663666
///
@@ -3816,7 +3816,7 @@ impl<T: ?Sized, A: Allocator> AsRef<T> for Arc<T, A> {
38163816
#[stable(feature = "pin", since = "1.33.0")]
38173817
impl<T: ?Sized, A: Allocator> Unpin for Arc<T, A> {}
38183818

3819-
/// Get the offset within an `ArcInner` for the payload behind a pointer.
3819+
/// Gets the offset within an `ArcInner` for the payload behind a pointer.
38203820
///
38213821
/// # Safety
38223822
///
@@ -3838,7 +3838,7 @@ fn data_offset_align(align: usize) -> usize {
38383838
layout.size() + layout.padding_needed_for(align)
38393839
}
38403840

3841-
/// A unique owning pointer to a [`ArcInner`] **that does not imply the contents are initialized,**
3841+
/// A unique owning pointer to an [`ArcInner`] **that does not imply the contents are initialized,**
38423842
/// but will deallocate it (without dropping the value) when dropped.
38433843
///
38443844
/// This is a helper for [`Arc::make_mut()`] to ensure correct cleanup on panic.
@@ -3851,7 +3851,7 @@ struct UniqueArcUninit<T: ?Sized, A: Allocator> {
38513851

38523852
#[cfg(not(no_global_oom_handling))]
38533853
impl<T: ?Sized, A: Allocator> UniqueArcUninit<T, A> {
3854-
/// Allocate a ArcInner with layout suitable to contain `for_value` or a clone of it.
3854+
/// Allocates an ArcInner with layout suitable to contain `for_value` or a clone of it.
38553855
fn new(for_value: &T, alloc: A) -> UniqueArcUninit<T, A> {
38563856
let layout = Layout::for_value(for_value);
38573857
let ptr = unsafe {

library/alloc/src/vec/into_iter.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ impl<T, A: Allocator> IntoIter<T, A> {
114114
}
115115

116116
/// Drops remaining elements and relinquishes the backing allocation.
117-
/// This method guarantees it won't panic before relinquishing
118-
/// the backing allocation.
117+
///
118+
/// This method guarantees it won't panic before relinquishing the backing
119+
/// allocation.
119120
///
120121
/// This is roughly equivalent to the following, but more efficient
121122
///

0 commit comments

Comments
 (0)