Skip to content

Commit bc52e15

Browse files
author
Alexander Regueiro
committed
libs: comments
1 parent cd7ca5e commit bc52e15

Some content is hidden

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

126 files changed

+474
-453
lines changed

src/liballoc/alloc.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! Memory allocation APIs
1+
//! Memory allocation APIs.
22
33
#![stable(feature = "alloc_module", since = "1.28.0")]
44

@@ -38,7 +38,7 @@ extern "Rust" {
3838
#[derive(Copy, Clone, Default, Debug)]
3939
pub struct Global;
4040

41-
/// Allocate memory with the global allocator.
41+
/// Allocates memory with the global allocator.
4242
///
4343
/// This function forwards calls to the [`GlobalAlloc::alloc`] method
4444
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -72,7 +72,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
7272
__rust_alloc(layout.size(), layout.align())
7373
}
7474

75-
/// Deallocate memory with the global allocator.
75+
/// Deallocates memory with the global allocator.
7676
///
7777
/// This function forwards calls to the [`GlobalAlloc::dealloc`] method
7878
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -90,7 +90,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
9090
__rust_dealloc(ptr, layout.size(), layout.align())
9191
}
9292

93-
/// Reallocate memory with the global allocator.
93+
/// Reallocates memory with the global allocator.
9494
///
9595
/// This function forwards calls to the [`GlobalAlloc::realloc`] method
9696
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -108,7 +108,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
108108
__rust_realloc(ptr, layout.size(), layout.align(), new_size)
109109
}
110110

111-
/// Allocate zero-initialized memory with the global allocator.
111+
/// Allocates zero-initialized memory with the global allocator.
112112
///
113113
/// This function forwards calls to the [`GlobalAlloc::alloc_zeroed`] method
114114
/// of the allocator registered with the `#[global_allocator]` attribute
@@ -170,6 +170,7 @@ unsafe impl Alloc for Global {
170170
}
171171

172172
/// The allocator for unique pointers.
173+
//
173174
// This function must not unwind. If it does, MIR codegen will fail.
174175
#[cfg(not(test))]
175176
#[lang = "exchange_malloc"]
@@ -194,14 +195,15 @@ pub(crate) unsafe fn box_free<T: ?Sized>(ptr: Unique<T>) {
194195
let ptr = ptr.as_ptr();
195196
let size = size_of_val(&*ptr);
196197
let align = min_align_of_val(&*ptr);
197-
// We do not allocate for Box<T> when T is ZST, so deallocation is also not necessary.
198+
// We do not allocate for `Box<T>` when `T` is zero-sized, so deallocation is also not
199+
// necessary.
198200
if size != 0 {
199201
let layout = Layout::from_size_align_unchecked(size, align);
200202
dealloc(ptr as *mut u8, layout);
201203
}
202204
}
203205

204-
/// Abort on memory allocation error or failure.
206+
/// Aborts on memory allocation error or failure.
205207
///
206208
/// Callers of memory allocation APIs wishing to abort computation
207209
/// in response to an allocation error are encouraged to call this function,

src/liballoc/boxed.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<T: ?Sized> Box<T> {
275275
#[stable(feature = "rust1", since = "1.0.0")]
276276
unsafe impl<#[may_dangle] T: ?Sized> Drop for Box<T> {
277277
fn drop(&mut self) {
278-
// FIXME: Do nothing, drop is currently performed by compiler.
278+
// FIXME: do nothing; drop is currently performed by compiler.
279279
}
280280
}
281281

src/liballoc/collections/binary_heap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
945945
}
946946
}
947947

948-
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
948+
// FIXME(#26925): Remove in favor of `#[derive(Clone)]`.
949949
#[stable(feature = "rust1", since = "1.0.0")]
950950
impl<'a, T> Clone for Iter<'a, T> {
951951
fn clone(&self) -> Iter<'a, T> {

src/liballoc/collections/btree/map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
887887
/// ```
888888
#[stable(feature = "rust1", since = "1.0.0")]
889889
pub fn entry(&mut self, key: K) -> Entry<'_, K, V> {
890-
// FIXME(@porglezomp) Avoid allocating if we don't insert
890+
// FIXME(porglezomp): avoid allocating if we don't insert.
891891
self.ensure_root_is_owned();
892892
match search::search_tree(self.root.as_mut(), &key) {
893893
Found(handle) => {

src/liballoc/collections/btree/node.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This is an attempt at an implementation following the ideal
1+
// This is an attempt at an implementation of the following ideal:
22
//
33
// ```
44
// struct BTreeMap<K, V> {
@@ -250,7 +250,7 @@ impl<K, V> Root<K, V> {
250250
NodeRef {
251251
height: self.height,
252252
node: self.node.as_ptr(),
253-
root: ptr::null_mut(), // FIXME: Is there anything better to do here?
253+
root: ptr::null_mut(), // FIXME: is there anything better to do here?
254254
_marker: PhantomData,
255255
}
256256
}
@@ -305,7 +305,7 @@ impl<K, V> Root<K, V> {
305305
}
306306
}
307307

308-
// N.B. `NodeRef` is always covariant in `K` and `V`, even when the `BorrowType`
308+
// N.B., `NodeRef` is always covariant in `K` and `V`, even when the `BorrowType`
309309
// is `Mut`. This is technically wrong, but cannot result in any unsafety due to
310310
// internal use of `NodeRef` because we stay completely generic over `K` and `V`.
311311
// However, whenever a public type wraps `NodeRef`, make sure that it has the
@@ -322,8 +322,8 @@ impl<K, V> Root<K, V> {
322322
/// `Leaf`, the `NodeRef` points to a leaf node, when this is `Internal` the
323323
/// `NodeRef` points to an internal node, and when this is `LeafOrInternal` the
324324
/// `NodeRef` could be pointing to either type of node.
325-
/// Note that in case of a leaf node, this might still be the shared root! Only turn
326-
/// this into a `LeafNode` reference if you know it is not a root! Shared references
325+
/// Note that in case of a leaf node, this might still be the shared root! Only turn
326+
/// this into a `LeafNode` reference if you know it is not a root! Shared references
327327
/// must be dereferencable *for the entire size of their pointee*, so `&InternalNode`
328328
/// pointing to the shared root is UB.
329329
/// Turning this into a `NodeHeader` is always safe.
@@ -562,7 +562,7 @@ impl<'a, K, V, Type> NodeRef<marker::Mut<'a>, K, V, Type> {
562562

563563
/// Returns a raw ptr to avoid asserting exclusive access to the entire node.
564564
fn as_leaf_mut(&mut self) -> *mut LeafNode<K, V> {
565-
// We are mutable, so we cannot be the root, so accessing this as a leaf is okay.
565+
// We are mutable, so we cannot be the root, so accessing this as a leaf is ok.
566566
self.node.as_ptr()
567567
}
568568

@@ -585,7 +585,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
585585
// We can sometimes do this even for the shared root, as the slice will be
586586
// empty. We cannot *always* do this because if the type is too highly
587587
// aligned, the offset of `keys` in a "full node" might be outside the bounds
588-
// of the header! So we do an alignment check first, that will be
588+
// of the header! So we do an alignment check first, that will be
589589
// evaluated at compile-time, and only do any run-time check in the rare case
590590
// that the alignment is very big.
591591
if mem::align_of::<K>() > mem::align_of::<LeafNode<(), ()>>() && self.is_shared_root() {
@@ -602,10 +602,10 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
602602
// and hence just adds a size-0-align-1 field, not affecting layout).
603603
// We know that we can transmute `NodeHeader<K, V, ()>` to `NodeHeader<K, V, K>`
604604
// because we did the alignment check above, and hence `NodeHeader<K, V, K>`
605-
// is not bigger than `NodeHeader<K, V, ()>`! Then we can use `NodeHeader<K, V, K>`
605+
// is not bigger than `NodeHeader<K, V, ()>`! Then we can use `NodeHeader<K, V, K>`
606606
// to compute the pointer where the keys start.
607607
// This entire hack will become unnecessary once
608-
// <https://github.com/rust-lang/rfcs/pull/2582> lands, then we can just take a raw
608+
// RFC #2582 lands, then we can just take a raw
609609
// pointer to the `keys` field of `*const InternalNode<K, V>`.
610610

611611
// This is a non-debug-assert because it can be completely compile-time evaluated.
@@ -620,7 +620,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> {
620620

621621
fn into_val_slice(self) -> &'a [V] {
622622
debug_assert!(!self.is_shared_root());
623-
// We cannot be the root, so `as_leaf` is okay
623+
// We cannot be the root, so `as_leaf` is ok
624624
unsafe {
625625
slice::from_raw_parts(
626626
MaybeUninit::first_ptr(&self.as_leaf().vals),

src/liballoc/collections/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
6969
}
7070
}
7171

72-
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
72+
// FIXME(#26925): Remove in favor of `#[derive(Clone)]`.
7373
#[stable(feature = "rust1", since = "1.0.0")]
7474
impl<T> Clone for Iter<'_, T> {
7575
fn clone(&self) -> Self {
@@ -1383,7 +1383,7 @@ mod tests {
13831383
// This caused the RHS's dtor to walk up into the LHS at drop and delete all of
13841384
// its nodes.
13851385
//
1386-
// https://github.com/rust-lang/rust/issues/26021
1386+
// Issue #26021.
13871387
let mut v1 = LinkedList::new();
13881388
v1.push_front(1);
13891389
v1.push_front(1);

src/liballoc/collections/vec_deque.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ impl<T> VecDeque<T> {
151151
wrap_index(idx.wrapping_sub(subtrahend), self.cap())
152152
}
153153

154-
/// Copies a contiguous block of memory len long from src to dst
154+
/// Copies a contiguous block of memory len long from `src` to `dst`.
155155
#[inline]
156156
unsafe fn copy(&self, dst: usize, src: usize, len: usize) {
157157
debug_assert!(dst + len <= self.cap(),
@@ -171,7 +171,7 @@ impl<T> VecDeque<T> {
171171
len);
172172
}
173173

174-
/// Copies a contiguous block of memory len long from src to dst
174+
/// Copies a contiguous block of memory len long from `src` to `dst`.
175175
#[inline]
176176
unsafe fn copy_nonoverlapping(&self, dst: usize, src: usize, len: usize) {
177177
debug_assert!(dst + len <= self.cap(),
@@ -191,9 +191,9 @@ impl<T> VecDeque<T> {
191191
len);
192192
}
193193

194-
/// Copies a potentially wrapping block of memory len long from src to dest.
195-
/// (abs(dst - src) + len) must be no larger than cap() (There must be at
196-
/// most one continuous overlapping region between src and dest).
194+
/// Copies a potentially wrapping block of memory len long from `src` to `dest`.
195+
/// `abs(dst - src) + len` must be no larger than `cap()`. (There must be at
196+
/// most one continuous overlapping region between `src` and `dest`).
197197
unsafe fn wrap_copy(&self, dst: usize, src: usize, len: usize) {
198198
#[allow(dead_code)]
199199
fn diff(a: usize, b: usize) -> usize {
@@ -219,7 +219,7 @@ impl<T> VecDeque<T> {
219219

220220
match (dst_after_src, src_wraps, dst_wraps) {
221221
(_, false, false) => {
222-
// src doesn't wrap, dst doesn't wrap
222+
// `src` doesn't wrap, `dst` doesn't wrap.
223223
//
224224
// S . . .
225225
// 1 [_ _ A A B B C C _]
@@ -229,7 +229,7 @@ impl<T> VecDeque<T> {
229229
self.copy(dst, src, len);
230230
}
231231
(false, false, true) => {
232-
// dst before src, src doesn't wrap, dst wraps
232+
// `dst` before `src`, `src` doesn't wrap, `dst` wraps.
233233
//
234234
// S . . .
235235
// 1 [A A B B _ _ _ C C]
@@ -241,7 +241,7 @@ impl<T> VecDeque<T> {
241241
self.copy(0, src + dst_pre_wrap_len, len - dst_pre_wrap_len);
242242
}
243243
(true, false, true) => {
244-
// src before dst, src doesn't wrap, dst wraps
244+
// `src` before `dst`, `src` doesn't wrap, `dst` wraps.
245245
//
246246
// S . . .
247247
// 1 [C C _ _ _ A A B B]
@@ -253,7 +253,7 @@ impl<T> VecDeque<T> {
253253
self.copy(dst, src, dst_pre_wrap_len);
254254
}
255255
(false, true, false) => {
256-
// dst before src, src wraps, dst doesn't wrap
256+
// `dst` before `src`, `src` wraps, `dst` doesn't wrap.
257257
//
258258
// . . S .
259259
// 1 [C C _ _ _ A A B B]
@@ -265,7 +265,7 @@ impl<T> VecDeque<T> {
265265
self.copy(dst + src_pre_wrap_len, 0, len - src_pre_wrap_len);
266266
}
267267
(true, true, false) => {
268-
// src before dst, src wraps, dst doesn't wrap
268+
// `src` before `dst`, `src` wraps, `dst` doesn't wrap.
269269
//
270270
// . . S .
271271
// 1 [A A B B _ _ _ C C]
@@ -277,7 +277,7 @@ impl<T> VecDeque<T> {
277277
self.copy(dst, src, src_pre_wrap_len);
278278
}
279279
(false, true, true) => {
280-
// dst before src, src wraps, dst wraps
280+
// `dst` before `src`, `src` wraps, `dst` wraps.
281281
//
282282
// . . . S .
283283
// 1 [A B C D _ E F G H]
@@ -293,7 +293,7 @@ impl<T> VecDeque<T> {
293293
self.copy(0, delta, len - dst_pre_wrap_len);
294294
}
295295
(true, true, true) => {
296-
// src before dst, src wraps, dst wraps
296+
// `src` before `dst`, `src` wraps, `dst` wraps.
297297
//
298298
// . . S . .
299299
// 1 [A B C D _ E F G H]
@@ -312,7 +312,7 @@ impl<T> VecDeque<T> {
312312
}
313313

314314
/// Frobs the head and tail sections around to handle the fact that we
315-
/// just reallocated. Unsafe because it trusts old_cap.
315+
/// just reallocated. Unsafe because it trusts `old_cap`.
316316
#[inline]
317317
unsafe fn handle_cap_increase(&mut self, old_cap: usize) {
318318
let new_cap = self.cap();
@@ -333,7 +333,7 @@ impl<T> VecDeque<T> {
333333

334334
if self.tail <= self.head {
335335
// A
336-
// Nop
336+
// No-op.
337337
} else if self.head < old_cap - self.tail {
338338
// B
339339
self.copy_nonoverlapping(old_cap, 0, self.head);
@@ -2130,7 +2130,7 @@ impl<T: fmt::Debug> fmt::Debug for Iter<'_, T> {
21302130
}
21312131
}
21322132

2133-
// FIXME(#26925) Remove in favor of `#[derive(Clone)]`
2133+
// FIXME(#26925): Remove in favor of `#[derive(Clone)]`.
21342134
#[stable(feature = "rust1", since = "1.0.0")]
21352135
impl<'a, T> Clone for Iter<'a, T> {
21362136
fn clone(&self) -> Iter<'a, T> {
@@ -3125,5 +3125,4 @@ mod tests {
31253125
assert_eq!(*a, 2);
31263126
}
31273127
}
3128-
31293128
}

src/liballoc/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@
205205
//! These two formatting traits have distinct purposes:
206206
//!
207207
//! - [`fmt::Display`][`Display`] implementations assert that the type can be faithfully
208-
//! represented as a UTF-8 string at all times. It is **not** expected that
208+
//! represented as a UTF-8 string at all times. It is *not* expected that
209209
//! all types implement the [`Display`] trait.
210210
//! - [`fmt::Debug`][`Debug`] implementations should be implemented for **all** public types.
211211
//! Output will typically represent the internal state as faithfully as possible.

src/liballoc/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ pub mod alloc;
135135
// Primitive types using the heaps above
136136

137137
// Need to conditionally define the mod from `boxed.rs` to avoid
138-
// duplicating the lang-items when building in test cfg; but also need
138+
// duplicating the lang-items when building in test cfg, but also need
139139
// to allow code to have `use boxed::Box;` declarations.
140140
#[cfg(not(test))]
141141
pub mod boxed;

src/liballoc/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ macro_rules! vec {
4646
($($x:expr,)*) => (vec![$($x),*])
4747
}
4848

49-
// HACK(japaric): with cfg(test) the inherent `[T]::into_vec` method, which is
49+
// HACK(japaric): with `cfg(test)`, the inherent `[T]::into_vec` method, which is
5050
// required for this macro definition, is not available. Instead use the
5151
// `slice::into_vec` function which is only available with cfg(test)
5252
// NB see the slice::hack module in slice.rs for more information

0 commit comments

Comments
 (0)