Skip to content

Tracking Issue for clone_from_ref #149075

Open

Description

@zachs18

Feature gate: #![feature(clone_from_ref)]

This is a tracking issue for Box::clone_from_ref, Arc::clone_from_ref, and Rc::clone_from_ref. try_* and *_in functions are under this tracking issue as well as allocator_api.

Allows creating a Box<T>/Rc<T>/Arc<T> by cloning from a &T where T: CloneToUninit. Notably, these work even when T is unsized (e.g. a slice).

Public API

// alloc::boxed

impl<T: ?Sized + CloneToUninit> Box<T> {
  pub fn clone_from_ref(val: &T) -> Box<T>;

  // also under feature(allocator_api)
  pub fn try_clone_from_ref(val: &T) -> Result<Box<T>, AllocError>;
}

impl<T: ?Sized + CloneToUninit, A: Allocator> Box<T, A> {
  // also under feature(allocator_api)
  pub fn clone_from_ref_in(val: &T, alloc: A) -> Box<T, A>;
  // also under feature(allocator_api)
  pub fn try_clone_from_ref_in(val: &T, alloc: A) -> Result<Box<T, A>, AllocError>;
}

// alloc::rc

impl<T: ?Sized + CloneToUninit> Rc<T> {
  pub fn clone_from_ref(val: &T) -> Rc<T>;

  // also under feature(allocator_api)
  pub fn try_clone_from_ref(val: &T) -> Result<Rc<T>, AllocError>;
}

impl<T: ?Sized + CloneToUninit, A: Allocator> Rc<T, A> {
  // also under feature(allocator_api)
  pub fn clone_from_ref_in(val: &T, alloc: A) -> Rc<T, A>;
  // also under feature(allocator_api)
  pub fn try_clone_from_ref_in(val: &T, alloc: A) -> Result<Rc<T, A>, AllocError>;
}

// alloc::sync

impl<T: ?Sized + CloneToUninit> Arc<T> {
  pub fn clone_from_ref(val: &T) -> Arc<T>;

  // also under feature(allocator_api)
  pub fn try_clone_from_ref(val: &T) -> Result<Arc<T>, AllocError>;
}

impl<T: ?Sized + CloneToUninit, A: Allocator> Arc<T, A> {
  // also under feature(allocator_api)
  pub fn clone_from_ref_in(val: &T, alloc: A) -> Arc<T, A>;
  // also under feature(allocator_api)
  pub fn try_clone_from_ref_in(val: &T, alloc: A) -> Result<Arc<T, A>, AllocError>;
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩

Activity

  1. added
    T-libs-api[DEPRECATED; DO NOT USE]
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    on Nov 19, 2025
  2. camsteffen commented on Nov 21, 2025

    @camsteffen
    Contributor

    Naming thoughts...

    It could be called just clone_from for consistency with Clone::clone{_from}. Cloning is always from a ref, so the _ref seems redundant.

    Or alternatively from_clone. This follows the very broad convention of T::from_* methods. It's a bit odd that it would be just swapping the words from Clone::clone_from, but that method is kinda niche so I don't think that would be too distracting.

    Rc::clone_from(_ref) looks a lot like Rc::clone, and it doesn't offer any hint that it is not taking another Rc as an argument. Rc::from_clone I think has a better tendency to communicate that we're creating from an inner value.

  3. added a commit that references this issue on Nov 26, 2025
  4. added 2 commits that reference this issue on Dec 10, 2025
  5. added a commit that references this issue on Jan 19, 2026
  6. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  7. added
    S-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.
    and removed on Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-needs-to-bakeStatus: The implementation is "complete" but it needs time to bake.T-libsRelevant to the library team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions