Skip to content

Commit aa81d32

Browse files
committed
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
2 parents 23e49dd + 6b75e3d commit aa81d32

File tree

8 files changed

+23
-23
lines changed

8 files changed

+23
-23
lines changed

library/core/src/pin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<P: Deref> Pin<P> {
541541
/// use std::pin::Pin;
542542
///
543543
/// fn move_pinned_rc<T>(mut x: Rc<T>) {
544-
/// let pinned = unsafe { Pin::new_unchecked(x.clone()) };
544+
/// let pinned = unsafe { Pin::new_unchecked(Rc::clone(&x)) };
545545
/// {
546546
/// let p: Pin<&T> = pinned.as_ref();
547547
/// // This should mean the pointee can never move again.

library/core/src/sync/atomic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
//! fn main() {
7777
//! let spinlock = Arc::new(AtomicUsize::new(1));
7878
//!
79-
//! let spinlock_clone = spinlock.clone();
79+
//! let spinlock_clone = Arc::clone(&spinlock);
8080
//! let thread = thread::spawn(move|| {
8181
//! spinlock_clone.store(0, Ordering::SeqCst);
8282
//! });

library/std/src/collections/hash/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2382,15 +2382,15 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
23822382
/// use std::rc::Rc;
23832383
///
23842384
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
2385-
/// let mut known_strings: Vec<Rc<String>> = Vec::new();
2385+
/// let known_strings: Vec<Rc<String>> = Vec::new();
23862386
///
23872387
/// // Initialise known strings, run program, etc.
23882388
///
23892389
/// reclaim_memory(&mut map, &known_strings);
23902390
///
23912391
/// fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) {
23922392
/// for s in known_strings {
2393-
/// if let Entry::Occupied(entry) = map.entry(s.clone()) {
2393+
/// if let Entry::Occupied(entry) = map.entry(Rc::clone(s)) {
23942394
/// // Replaces the entry's key with our version of it in `known_strings`.
23952395
/// entry.replace_key();
23962396
/// }

library/std/src/sync/barrier.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::sync::{Condvar, Mutex};
1616
/// let mut handles = Vec::with_capacity(10);
1717
/// let barrier = Arc::new(Barrier::new(10));
1818
/// for _ in 0..10 {
19-
/// let c = barrier.clone();
19+
/// let c = Arc::clone(&barrier);
2020
/// // The same messages will be printed together.
2121
/// // You will NOT see any interleaving.
2222
/// handles.push(thread::spawn(move|| {
@@ -113,7 +113,7 @@ impl Barrier {
113113
/// let mut handles = Vec::with_capacity(10);
114114
/// let barrier = Arc::new(Barrier::new(10));
115115
/// for _ in 0..10 {
116-
/// let c = barrier.clone();
116+
/// let c = Arc::clone(&barrier);
117117
/// // The same messages will be printed together.
118118
/// // You will NOT see any interleaving.
119119
/// handles.push(thread::spawn(move|| {

library/std/src/sync/condvar.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl WaitTimeoutResult {
3636
/// use std::time::Duration;
3737
///
3838
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
39-
/// let pair2 = pair.clone();
39+
/// let pair2 = Arc::clone(&pair);
4040
///
4141
/// thread::spawn(move || {
4242
/// let (lock, cvar) = &*pair2;
@@ -93,7 +93,7 @@ impl WaitTimeoutResult {
9393
/// use std::thread;
9494
///
9595
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
96-
/// let pair2 = pair.clone();
96+
/// let pair2 = Arc::clone(&pair);
9797
///
9898
/// // Inside of our lock, spawn a new thread, and then wait for it to start.
9999
/// thread::spawn(move|| {
@@ -176,7 +176,7 @@ impl Condvar {
176176
/// use std::thread;
177177
///
178178
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
179-
/// let pair2 = pair.clone();
179+
/// let pair2 = Arc::clone(&pair);
180180
///
181181
/// thread::spawn(move|| {
182182
/// let (lock, cvar) = &*pair2;
@@ -232,7 +232,7 @@ impl Condvar {
232232
/// use std::thread;
233233
///
234234
/// let pair = Arc::new((Mutex::new(true), Condvar::new()));
235-
/// let pair2 = pair.clone();
235+
/// let pair2 = Arc::clone(&pair);
236236
///
237237
/// thread::spawn(move|| {
238238
/// let (lock, cvar) = &*pair2;
@@ -291,7 +291,7 @@ impl Condvar {
291291
/// use std::thread;
292292
///
293293
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
294-
/// let pair2 = pair.clone();
294+
/// let pair2 = Arc::clone(&pair);
295295
///
296296
/// thread::spawn(move|| {
297297
/// let (lock, cvar) = &*pair2;
@@ -363,7 +363,7 @@ impl Condvar {
363363
/// use std::time::Duration;
364364
///
365365
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
366-
/// let pair2 = pair.clone();
366+
/// let pair2 = Arc::clone(&pair);
367367
///
368368
/// thread::spawn(move|| {
369369
/// let (lock, cvar) = &*pair2;
@@ -432,7 +432,7 @@ impl Condvar {
432432
/// use std::time::Duration;
433433
///
434434
/// let pair = Arc::new((Mutex::new(true), Condvar::new()));
435-
/// let pair2 = pair.clone();
435+
/// let pair2 = Arc::clone(&pair);
436436
///
437437
/// thread::spawn(move|| {
438438
/// let (lock, cvar) = &*pair2;
@@ -496,7 +496,7 @@ impl Condvar {
496496
/// use std::thread;
497497
///
498498
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
499-
/// let pair2 = pair.clone();
499+
/// let pair2 = Arc::clone(&pair);
500500
///
501501
/// thread::spawn(move|| {
502502
/// let (lock, cvar) = &*pair2;
@@ -536,7 +536,7 @@ impl Condvar {
536536
/// use std::thread;
537537
///
538538
/// let pair = Arc::new((Mutex::new(false), Condvar::new()));
539-
/// let pair2 = pair.clone();
539+
/// let pair2 = Arc::clone(&pair);
540540
///
541541
/// thread::spawn(move|| {
542542
/// let (lock, cvar) = &*pair2;

library/std/src/sync/mutex.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
8888
/// use std::thread;
8989
///
9090
/// let lock = Arc::new(Mutex::new(0_u32));
91-
/// let lock2 = lock.clone();
91+
/// let lock2 = Arc::clone(&lock);
9292
///
9393
/// let _ = thread::spawn(move || -> () {
9494
/// // This thread will acquire the mutex first, unwrapping the result of
@@ -259,7 +259,7 @@ impl<T: ?Sized> Mutex<T> {
259259
/// use std::thread;
260260
///
261261
/// let mutex = Arc::new(Mutex::new(0));
262-
/// let c_mutex = mutex.clone();
262+
/// let c_mutex = Arc::clone(&mutex);
263263
///
264264
/// thread::spawn(move || {
265265
/// *c_mutex.lock().unwrap() = 10;
@@ -295,7 +295,7 @@ impl<T: ?Sized> Mutex<T> {
295295
/// use std::thread;
296296
///
297297
/// let mutex = Arc::new(Mutex::new(0));
298-
/// let c_mutex = mutex.clone();
298+
/// let c_mutex = Arc::clone(&mutex);
299299
///
300300
/// thread::spawn(move || {
301301
/// let mut lock = c_mutex.try_lock();
@@ -331,7 +331,7 @@ impl<T: ?Sized> Mutex<T> {
331331
/// use std::thread;
332332
///
333333
/// let mutex = Arc::new(Mutex::new(0));
334-
/// let c_mutex = mutex.clone();
334+
/// let c_mutex = Arc::clone(&mutex);
335335
///
336336
/// let _ = thread::spawn(move || {
337337
/// let _lock = c_mutex.lock().unwrap();

library/std/src/sync/rwlock.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ impl<T: ?Sized> RwLock<T> {
165165
/// use std::thread;
166166
///
167167
/// let lock = Arc::new(RwLock::new(1));
168-
/// let c_lock = lock.clone();
168+
/// let c_lock = Arc::clone(&lock);
169169
///
170170
/// let n = lock.read().unwrap();
171171
/// assert_eq!(*n, 1);
@@ -321,7 +321,7 @@ impl<T: ?Sized> RwLock<T> {
321321
/// use std::thread;
322322
///
323323
/// let lock = Arc::new(RwLock::new(0));
324-
/// let c_lock = lock.clone();
324+
/// let c_lock = Arc::clone(&lock);
325325
///
326326
/// let _ = thread::spawn(move || {
327327
/// let _lock = c_lock.write().unwrap();

library/std/src/sys_common/poison.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ pub struct Guard {
6565
/// let mutex = Arc::new(Mutex::new(1));
6666
///
6767
/// // poison the mutex
68-
/// let c_mutex = mutex.clone();
68+
/// let c_mutex = Arc::clone(&mutex);
6969
/// let _ = thread::spawn(move || {
7070
/// let mut data = c_mutex.lock().unwrap();
7171
/// *data = 2;
@@ -168,7 +168,7 @@ impl<T> PoisonError<T> {
168168
/// let mutex = Arc::new(Mutex::new(HashSet::new()));
169169
///
170170
/// // poison the mutex
171-
/// let c_mutex = mutex.clone();
171+
/// let c_mutex = Arc::clone(&mutex);
172172
/// let _ = thread::spawn(move || {
173173
/// let mut data = c_mutex.lock().unwrap();
174174
/// data.insert(10);

0 commit comments

Comments
 (0)