about summary refs log tree commit diff
path: root/library/core/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-08-19 06:59:13 +0000
committerbors <bors@rust-lang.org>2020-08-19 06:59:13 +0000
commit5b04bbfcbb79ed7325ea2b580458a80d95da6bbb (patch)
tree54f153779798d43bf66667e385982b6d2f9f9711 /library/core/src
parentc03c213daf5fe3b52c768b4f145e45d8994d87ea (diff)
parent07ea340e89a4938a26039bceac6dbc1376978a48 (diff)
downloadrust-5b04bbfcbb79ed7325ea2b580458a80d95da6bbb.tar.gz
rust-5b04bbfcbb79ed7325ea2b580458a80d95da6bbb.zip
Auto merge of #75692 - JohnTitor:rollup-8gr04ah, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #75038 (See also X-Link mem::{swap, take, replace})
 - #75049 (docs(marker/copy): provide example for `&T` being `Copy`)
 - #75499 (Fix documentation error)
 - #75554 (Fix clashing_extern_declarations stack overflow for recursive types.)
 - #75646 (Move to intra doc links for keyword documentation)
 - #75652 (Resolve true and false as booleans)
 - #75658 (Don't emit "is not a logical operator" error outside of associative expressions)
 - #75665 (Add doc examples coverage)
 - #75685 (Switch to intra-doc links in /src/sys/unix/ext/*.rs)

Failed merges:

r? @ghost
Diffstat (limited to 'library/core/src')
-rw-r--r--library/core/src/marker.rs15
-rw-r--r--library/core/src/mem/mod.rs16
-rw-r--r--library/core/src/str/mod.rs2
3 files changed, 32 insertions, 1 deletions
diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs
index 56dddee7b77..9326aaf5684 100644
--- a/library/core/src/marker.rs
+++ b/library/core/src/marker.rs
@@ -291,6 +291,7 @@ pub trait StructuralEq {
 ///
 /// ```
 /// # #[allow(dead_code)]
+/// #[derive(Copy, Clone)]
 /// struct Point {
 ///    x: i32,
 ///    y: i32,
@@ -315,6 +316,20 @@ pub trait StructuralEq {
 /// the trait `Copy` may not be implemented for this type; field `points` does not implement `Copy`
 /// ```
 ///
+/// Shared references (`&T`) are also `Copy`, so a type can be `Copy`, even when it holds
+/// shared references of types `T` that are *not* `Copy`. Consider the following struct,
+/// which can implement `Copy`, because it only holds a *shared reference* to our non-`Copy`
+/// type `PointList` from above:
+///
+/// ```
+/// # #![allow(dead_code)]
+/// # struct PointList;
+/// #[derive(Copy, Clone)]
+/// struct PointListWrapper<'a> {
+///     point_list_ref: &'a PointList,
+/// }
+/// ```
+///
 /// ## When *can't* my type be `Copy`?
 ///
 /// Some types can't be copied safely. For example, copying `&mut T` would create an aliased
diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs
index 4e58e118562..9107c570a89 100644
--- a/library/core/src/mem/mod.rs
+++ b/library/core/src/mem/mod.rs
@@ -670,6 +670,9 @@ pub unsafe fn uninitialized<T>() -> T {
 
 /// Swaps the values at two mutable locations, without deinitializing either one.
 ///
+/// * If you want to swap with a default or dummy value, see [`take`].
+/// * If you want to swap with a passed value, returning the old value, see [`replace`].
+///
 /// # Examples
 ///
 /// ```
@@ -683,6 +686,9 @@ pub unsafe fn uninitialized<T>() -> T {
 /// assert_eq!(42, x);
 /// assert_eq!(5, y);
 /// ```
+///
+/// [`replace`]: fn.replace.html
+/// [`take`]: fn.take.html
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub fn swap<T>(x: &mut T, y: &mut T) {
@@ -695,6 +701,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
 
 /// Replaces `dest` with the default value of `T`, returning the previous `dest` value.
 ///
+/// * If you want to replace the values of two variables, see [`swap`].
+/// * If you want to replace with a passed value instead of the default value, see [`replace`].
+///
 /// # Examples
 ///
 /// A simple example:
@@ -747,6 +756,8 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
 /// ```
 ///
 /// [`Clone`]: ../../std/clone/trait.Clone.html
+/// [`replace`]: fn.replace.html
+/// [`swap`]: fn.swap.html
 #[inline]
 #[stable(feature = "mem_take", since = "1.40.0")]
 pub fn take<T: Default>(dest: &mut T) -> T {
@@ -757,6 +768,9 @@ pub fn take<T: Default>(dest: &mut T) -> T {
 ///
 /// Neither value is dropped.
 ///
+/// * If you want to replace the values of two variables, see [`swap`].
+/// * If you want to replace with a default value, see [`take`].
+///
 /// # Examples
 ///
 /// A simple example:
@@ -810,6 +824,8 @@ pub fn take<T: Default>(dest: &mut T) -> T {
 /// ```
 ///
 /// [`Clone`]: ../../std/clone/trait.Clone.html
+/// [`swap`]: fn.swap.html
+/// [`take`]: fn.take.html
 #[inline]
 #[stable(feature = "rust1", since = "1.0.0")]
 #[must_use = "if you don't need the old value, you can just assign the new value directly"]
diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs
index 934f581f3fa..4705c984bd4 100644
--- a/library/core/src/str/mod.rs
+++ b/library/core/src/str/mod.rs
@@ -2031,7 +2031,7 @@ mod traits {
     /// # Panics
     ///
     /// Panics if `begin` does not point to the starting byte offset of
-    /// a character (as defined by `is_char_boundary`), or if `begin >= len`.
+    /// a character (as defined by `is_char_boundary`), or if `begin > len`.
     #[stable(feature = "str_checked_slicing", since = "1.20.0")]
     unsafe impl SliceIndex<str> for ops::RangeFrom<usize> {
         type Output = str;