Skip to content

Commit c698361

Browse files
committed
Update CloneToUninit example to use Box
1 parent f8df2e1 commit c698361

File tree

1 file changed

+7
-12
lines changed

1 file changed

+7
-12
lines changed

library/core/src/clone.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,14 @@ pub struct AssertParamIsCopy<T: Copy + PointeeSized> {
356356
///
357357
/// # Examples
358358
///
359-
// FIXME(#126799): when `Box::clone` allows use of `CloneToUninit`, rewrite these examples with it
360-
// since `Rc` is a distraction.
361359
///
362360
/// If you are defining a trait, you can add `CloneToUninit` as a supertrait to enable cloning of
363361
/// `dyn` values of your trait:
364362
///
365363
/// ```
366364
/// #![feature(clone_to_uninit)]
367-
/// use std::rc::Rc;
368365
///
369-
/// trait Foo: std::fmt::Debug + std::clone::CloneToUninit {
366+
/// trait Foo: std::clone::CloneToUninit {
370367
/// fn modify(&mut self);
371368
/// fn value(&self) -> i32;
372369
/// }
@@ -380,10 +377,10 @@ pub struct AssertParamIsCopy<T: Copy + PointeeSized> {
380377
/// }
381378
/// }
382379
///
383-
/// let first: Rc<dyn Foo> = Rc::new(1234);
380+
/// let first: Box<dyn Foo> = Box::new(1234);
384381
///
385-
/// let mut second = first.clone();
386-
/// Rc::make_mut(&mut second).modify(); // make_mut() will call clone_to_uninit()
382+
/// let mut second = first.clone(); // clone() will call clone_to_uninit()
383+
/// second.modify();
387384
///
388385
/// assert_eq!(first.value(), 1234);
389386
/// assert_eq!(second.value(), 12340);
@@ -397,7 +394,6 @@ pub struct AssertParamIsCopy<T: Copy + PointeeSized> {
397394
/// #![feature(clone_to_uninit)]
398395
/// use std::clone::CloneToUninit;
399396
/// use std::mem::offset_of;
400-
/// use std::rc::Rc;
401397
///
402398
/// #[derive(PartialEq)]
403399
/// struct MyDst<T: ?Sized> {
@@ -453,14 +449,13 @@ pub struct AssertParamIsCopy<T: Copy + PointeeSized> {
453449
///
454450
/// fn main() {
455451
/// // Construct MyDst<[u8; 4]>, then coerce to MyDst<[u8]>.
456-
/// let first: Rc<MyDst<[u8]>> = Rc::new(MyDst {
452+
/// let first: Box<MyDst<[u8]>> = Box::new(MyDst {
457453
/// label: String::from("hello"),
458454
/// contents: [1, 2, 3, 4],
459455
/// });
460456
///
461-
/// let mut second = first.clone();
462-
/// // make_mut() will call clone_to_uninit().
463-
/// for elem in Rc::make_mut(&mut second).contents.iter_mut() {
457+
/// let mut second = first.clone(); // clone() will call clone_to_uninit().
458+
/// for elem in second.contents.iter_mut() {
464459
/// *elem *= 10;
465460
/// }
466461
///

0 commit comments

Comments
 (0)