Auto merge of #76128 - poliorcetics:doc-use-arc-clone, r=KodrAus

Use Arc::clone and Rc::clone in documentation

This PR replaces uses of `x.clone()` by `Rc::clone(&x)` (or `Arc::clone(&x)`) to better match the documentation for those types.

@rustbot modify labels: T-doc
This commit is contained in:
bors 2020-09-06 12:34:31 +00:00
commit aa81d32165
8 changed files with 23 additions and 23 deletions

View File

@ -541,7 +541,7 @@ impl<P: Deref> Pin<P> {
/// use std::pin::Pin; /// use std::pin::Pin;
/// ///
/// fn move_pinned_rc<T>(mut x: Rc<T>) { /// fn move_pinned_rc<T>(mut x: Rc<T>) {
/// let pinned = unsafe { Pin::new_unchecked(x.clone()) }; /// let pinned = unsafe { Pin::new_unchecked(Rc::clone(&x)) };
/// { /// {
/// let p: Pin<&T> = pinned.as_ref(); /// let p: Pin<&T> = pinned.as_ref();
/// // This should mean the pointee can never move again. /// // This should mean the pointee can never move again.

View File

@ -76,7 +76,7 @@
//! fn main() { //! fn main() {
//! let spinlock = Arc::new(AtomicUsize::new(1)); //! let spinlock = Arc::new(AtomicUsize::new(1));
//! //!
//! let spinlock_clone = spinlock.clone(); //! let spinlock_clone = Arc::clone(&spinlock);
//! let thread = thread::spawn(move|| { //! let thread = thread::spawn(move|| {
//! spinlock_clone.store(0, Ordering::SeqCst); //! spinlock_clone.store(0, Ordering::SeqCst);
//! }); //! });

View File

@ -2382,7 +2382,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
/// use std::rc::Rc; /// use std::rc::Rc;
/// ///
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new(); /// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
/// let mut known_strings: Vec<Rc<String>> = Vec::new(); /// let known_strings: Vec<Rc<String>> = Vec::new();
/// ///
/// // Initialise known strings, run program, etc. /// // Initialise known strings, run program, etc.
/// ///
@ -2390,7 +2390,7 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
/// ///
/// fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) { /// fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) {
/// for s in known_strings { /// for s in known_strings {
/// if let Entry::Occupied(entry) = map.entry(s.clone()) { /// if let Entry::Occupied(entry) = map.entry(Rc::clone(s)) {
/// // Replaces the entry's key with our version of it in `known_strings`. /// // Replaces the entry's key with our version of it in `known_strings`.
/// entry.replace_key(); /// entry.replace_key();
/// } /// }

View File

@ -16,7 +16,7 @@ use crate::sync::{Condvar, Mutex};
/// let mut handles = Vec::with_capacity(10); /// let mut handles = Vec::with_capacity(10);
/// let barrier = Arc::new(Barrier::new(10)); /// let barrier = Arc::new(Barrier::new(10));
/// for _ in 0..10 { /// for _ in 0..10 {
/// let c = barrier.clone(); /// let c = Arc::clone(&barrier);
/// // The same messages will be printed together. /// // The same messages will be printed together.
/// // You will NOT see any interleaving. /// // You will NOT see any interleaving.
/// handles.push(thread::spawn(move|| { /// handles.push(thread::spawn(move|| {
@ -113,7 +113,7 @@ impl Barrier {
/// let mut handles = Vec::with_capacity(10); /// let mut handles = Vec::with_capacity(10);
/// let barrier = Arc::new(Barrier::new(10)); /// let barrier = Arc::new(Barrier::new(10));
/// for _ in 0..10 { /// for _ in 0..10 {
/// let c = barrier.clone(); /// let c = Arc::clone(&barrier);
/// // The same messages will be printed together. /// // The same messages will be printed together.
/// // You will NOT see any interleaving. /// // You will NOT see any interleaving.
/// handles.push(thread::spawn(move|| { /// handles.push(thread::spawn(move|| {

View File

@ -36,7 +36,7 @@ impl WaitTimeoutResult {
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move || { /// thread::spawn(move || {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -93,7 +93,7 @@ impl WaitTimeoutResult {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// // Inside of our lock, spawn a new thread, and then wait for it to start. /// // Inside of our lock, spawn a new thread, and then wait for it to start.
/// thread::spawn(move|| { /// thread::spawn(move|| {
@ -176,7 +176,7 @@ impl Condvar {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -232,7 +232,7 @@ impl Condvar {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(true), Condvar::new())); /// let pair = Arc::new((Mutex::new(true), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -291,7 +291,7 @@ impl Condvar {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -363,7 +363,7 @@ impl Condvar {
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -432,7 +432,7 @@ impl Condvar {
/// use std::time::Duration; /// use std::time::Duration;
/// ///
/// let pair = Arc::new((Mutex::new(true), Condvar::new())); /// let pair = Arc::new((Mutex::new(true), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -496,7 +496,7 @@ impl Condvar {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;
@ -536,7 +536,7 @@ impl Condvar {
/// use std::thread; /// use std::thread;
/// ///
/// let pair = Arc::new((Mutex::new(false), Condvar::new())); /// let pair = Arc::new((Mutex::new(false), Condvar::new()));
/// let pair2 = pair.clone(); /// let pair2 = Arc::clone(&pair);
/// ///
/// thread::spawn(move|| { /// thread::spawn(move|| {
/// let (lock, cvar) = &*pair2; /// let (lock, cvar) = &*pair2;

View File

@ -88,7 +88,7 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
/// use std::thread; /// use std::thread;
/// ///
/// let lock = Arc::new(Mutex::new(0_u32)); /// let lock = Arc::new(Mutex::new(0_u32));
/// let lock2 = lock.clone(); /// let lock2 = Arc::clone(&lock);
/// ///
/// let _ = thread::spawn(move || -> () { /// let _ = thread::spawn(move || -> () {
/// // This thread will acquire the mutex first, unwrapping the result of /// // This thread will acquire the mutex first, unwrapping the result of
@ -259,7 +259,7 @@ impl<T: ?Sized> Mutex<T> {
/// use std::thread; /// use std::thread;
/// ///
/// let mutex = Arc::new(Mutex::new(0)); /// let mutex = Arc::new(Mutex::new(0));
/// let c_mutex = mutex.clone(); /// let c_mutex = Arc::clone(&mutex);
/// ///
/// thread::spawn(move || { /// thread::spawn(move || {
/// *c_mutex.lock().unwrap() = 10; /// *c_mutex.lock().unwrap() = 10;
@ -295,7 +295,7 @@ impl<T: ?Sized> Mutex<T> {
/// use std::thread; /// use std::thread;
/// ///
/// let mutex = Arc::new(Mutex::new(0)); /// let mutex = Arc::new(Mutex::new(0));
/// let c_mutex = mutex.clone(); /// let c_mutex = Arc::clone(&mutex);
/// ///
/// thread::spawn(move || { /// thread::spawn(move || {
/// let mut lock = c_mutex.try_lock(); /// let mut lock = c_mutex.try_lock();
@ -331,7 +331,7 @@ impl<T: ?Sized> Mutex<T> {
/// use std::thread; /// use std::thread;
/// ///
/// let mutex = Arc::new(Mutex::new(0)); /// let mutex = Arc::new(Mutex::new(0));
/// let c_mutex = mutex.clone(); /// let c_mutex = Arc::clone(&mutex);
/// ///
/// let _ = thread::spawn(move || { /// let _ = thread::spawn(move || {
/// let _lock = c_mutex.lock().unwrap(); /// let _lock = c_mutex.lock().unwrap();

View File

@ -165,7 +165,7 @@ impl<T: ?Sized> RwLock<T> {
/// use std::thread; /// use std::thread;
/// ///
/// let lock = Arc::new(RwLock::new(1)); /// let lock = Arc::new(RwLock::new(1));
/// let c_lock = lock.clone(); /// let c_lock = Arc::clone(&lock);
/// ///
/// let n = lock.read().unwrap(); /// let n = lock.read().unwrap();
/// assert_eq!(*n, 1); /// assert_eq!(*n, 1);
@ -321,7 +321,7 @@ impl<T: ?Sized> RwLock<T> {
/// use std::thread; /// use std::thread;
/// ///
/// let lock = Arc::new(RwLock::new(0)); /// let lock = Arc::new(RwLock::new(0));
/// let c_lock = lock.clone(); /// let c_lock = Arc::clone(&lock);
/// ///
/// let _ = thread::spawn(move || { /// let _ = thread::spawn(move || {
/// let _lock = c_lock.write().unwrap(); /// let _lock = c_lock.write().unwrap();

View File

@ -65,7 +65,7 @@ pub struct Guard {
/// let mutex = Arc::new(Mutex::new(1)); /// let mutex = Arc::new(Mutex::new(1));
/// ///
/// // poison the mutex /// // poison the mutex
/// let c_mutex = mutex.clone(); /// let c_mutex = Arc::clone(&mutex);
/// let _ = thread::spawn(move || { /// let _ = thread::spawn(move || {
/// let mut data = c_mutex.lock().unwrap(); /// let mut data = c_mutex.lock().unwrap();
/// *data = 2; /// *data = 2;
@ -168,7 +168,7 @@ impl<T> PoisonError<T> {
/// let mutex = Arc::new(Mutex::new(HashSet::new())); /// let mutex = Arc::new(Mutex::new(HashSet::new()));
/// ///
/// // poison the mutex /// // poison the mutex
/// let c_mutex = mutex.clone(); /// let c_mutex = Arc::clone(&mutex);
/// let _ = thread::spawn(move || { /// let _ = thread::spawn(move || {
/// let mut data = c_mutex.lock().unwrap(); /// let mut data = c_mutex.lock().unwrap();
/// data.insert(10); /// data.insert(10);