Skip to content

Commit 838002d

Browse files
authored
Rollup merge of #61599 - laumann:pin-docs-minor-edits, r=Centril
libcore/pin: Minor grammar corrections for module documentation This is by no means exhaustive, but I noticed a few grammatical errors when reading the documentation, and decided just to push these. Some standard rules/guidelines I followed: * Do not split infinitives, ie "not to move" instead of "to not move" * Do not use "since" when you want to say "because" or "as" - the word "since" has a temporal meaning In addition: * Fix a small typo: "Similarily" should be "Similarly" * Delete double-spaces after full stop
2 parents 46412ba + fb61b85 commit 838002d

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/libcore/pin.rs

+21-20
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! Types that pin data to its location in memory.
22
//!
3-
//! It is sometimes useful to have objects that are guaranteed to not move,
3+
//! It is sometimes useful to have objects that are guaranteed not to move,
44
//! in the sense that their placement in memory does not change, and can thus be relied upon.
55
//! A prime example of such a scenario would be building self-referential structs,
6-
//! since moving an object with pointers to itself will invalidate them,
7-
//! which could cause undefined behavior.
6+
//! as moving an object with pointers to itself will invalidate them, which could cause undefined
7+
//! behavior.
88
//!
99
//! A [`Pin<P>`] ensures that the pointee of any pointer type `P` has a stable location in memory,
1010
//! meaning it cannot be moved elsewhere and its memory cannot be deallocated
@@ -15,9 +15,10 @@
1515
//! moving the values they contain: you can move out of a `Box<T>`, or you can use [`mem::swap`].
1616
//! [`Pin<P>`] wraps a pointer type `P`, so `Pin<Box<T>>` functions much like a regular `Box<T>`:
1717
//! when a `Pin<Box<T>>` gets dropped, so do its contents, and the memory gets deallocated.
18-
//! Similarily, `Pin<&mut T>` is a lot like `&mut T`. However, [`Pin<P>`] does not let clients
18+
//! Similarly, `Pin<&mut T>` is a lot like `&mut T`. However, [`Pin<P>`] does not let clients
1919
//! actually obtain a `Box<T>` or `&mut T` to pinned data, which implies that you cannot use
2020
//! operations such as [`mem::swap`]:
21+
//!
2122
//! ```
2223
//! use std::pin::Pin;
2324
//! fn swap_pins<T>(x: Pin<&mut T>, y: Pin<&mut T>) {
@@ -39,19 +40,19 @@
3940
//! as a "`P`-style pointer" to a pinned `P::Target` -- so, a `Pin<Box<T>>` is
4041
//! an owned pointer to a pinned `T`, and a `Pin<Rc<T>>` is a reference-counted
4142
//! pointer to a pinned `T`.
42-
//! For correctness, [`Pin<P>`] relies on the [`Deref`] and [`DerefMut`] implementations
43-
//! to not move out of their `self` parameter, and to only ever return a pointer
44-
//! to pinned data when they are called on a pinned pointer.
43+
//! For correctness, [`Pin<P>`] relies on the implementations of [`Deref`] and
44+
//! [`DerefMut`] not to move out of their `self` parameter, and only ever to
45+
//! return a pointer to pinned data when they are called on a pinned pointer.
4546
//!
4647
//! # `Unpin`
4748
//!
48-
//! However, these restrictions are usually not necessary. Many types are always freely
49-
//! movable, even when pinned, because they do not rely on having a stable address.
50-
//! This includes all the basic types (like `bool`, `i32`, references)
51-
//! as well as types consisting solely of these types.
52-
//! Types that do not care about pinning implement the [`Unpin`] auto-trait, which
53-
//! cancels the effect of [`Pin<P>`]. For `T: Unpin`, `Pin<Box<T>>` and `Box<T>` function
54-
//! identically, as do `Pin<&mut T>` and `&mut T`.
49+
//! Many types are always freely movable, even when pinned, because they do not
50+
//! rely on having a stable address. This includes all the basic types (like
51+
//! `bool`, `i32`, and references) as well as types consisting solely of these
52+
//! types. Types that do not care about pinning implement the [`Unpin`]
53+
//! auto-trait, which cancels the effect of [`Pin<P>`]. For `T: Unpin`,
54+
//! `Pin<Box<T>>` and `Box<T>` function identically, as do `Pin<&mut T>` and
55+
//! `&mut T`.
5556
//!
5657
//! Note that pinning and `Unpin` only affect the pointed-to type `P::Target`, not the pointer
5758
//! type `P` itself that got wrapped in `Pin<P>`. For example, whether or not `Box<T>` is
@@ -65,11 +66,11 @@
6566
//! use std::marker::PhantomPinned;
6667
//! use std::ptr::NonNull;
6768
//!
68-
//! // This is a self-referential struct since the slice field points to the data field.
69+
//! // This is a self-referential struct because the slice field points to the data field.
6970
//! // We cannot inform the compiler about that with a normal reference,
70-
//! // since this pattern cannot be described with the usual borrowing rules.
71-
//! // Instead we use a raw pointer, though one which is known to not be null,
72-
//! // since we know it's pointing at the string.
71+
//! // as this pattern cannot be described with the usual borrowing rules.
72+
//! // Instead we use a raw pointer, though one which is known not to be null,
73+
//! // as we know it's pointing at the string.
7374
//! struct Unmovable {
7475
//! data: String,
7576
//! slice: NonNull<String>,
@@ -146,7 +147,7 @@
146147
//! section needs to function correctly.
147148
//!
148149
//! Notice that this guarantee does *not* mean that memory does not leak! It is still
149-
//! completely okay not to ever call `drop` on a pinned element (e.g., you can still
150+
//! completely okay not ever to call `drop` on a pinned element (e.g., you can still
150151
//! call [`mem::forget`] on a `Pin<Box<T>>`). In the example of the doubly-linked
151152
//! list, that element would just stay in the list. However you may not free or reuse the storage
152153
//! *without calling `drop`*.
@@ -192,7 +193,7 @@
192193
//! `Unpin`. This is the default, but `Unpin` is a safe trait, so as the author of
193194
//! the wrapper it is your responsibility *not* to add something like
194195
//! `impl<T> Unpin for Wrapper<T>`. (Notice that adding a projection operation
195-
//! requires unsafe code, so the fact that `Unpin` is a safe trait does not break
196+
//! requires unsafe code, so the fact that `Unpin` is a safe trait does not break
196197
//! the principle that you only have to worry about any of this if you use `unsafe`.)
197198
//! 2. The destructor of the wrapper must not move structural fields out of its argument. This
198199
//! is the exact point that was raised in the [previous section][drop-impl]: `drop` takes

0 commit comments

Comments
 (0)