rust-lang / rust-lang/rust

Tracking Issue for `cell_get_cloned`

Open
#145,329 45 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-tracking-issue I-lang-radar S-tracking-unimplemented T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

Feature gate: #![feature(cell_get_cloned)]

This is a tracking issue for Cell::get_cloned for T: CloneFromCopy (e.g. Rc<T>, Arc<T>, etc.).

ACP: https://github.com/rust-lang/libs-team/issues/572

Public API
/// Safety: can call `Self::clone(&*ManuallyDrop::new(ptr::read(ptr_to_self)))`
#[marker]
pub unsafe trait CloneFromCell: Clone {}

// Can't do this, unsound
// unsafe impl<T: Copy> CloneFromCell for T {}

unsafe impl<T: ?Sized> CloneFromCell for Rc<T> {}
unsafe impl<T: ?Sized> CloneFromCell for Arc<T> {}
unsafe impl<T: ?Sized> CloneFromCell for rc::Weak<T> {}
unsafe impl<T: ?Sized> CloneFromCell for sync::Weak<T> {}

// basically all std types that don't have indirection:
unsafe impl<T: CloneFromCell, const N: usize> CloneFromCell for [T; N] {}
unsafe impl<T: CloneFromCell> CloneFromCell for Option<T> {}
unsafe impl<T: CloneFromCell, E: CloneFromCell> CloneFromCell for Result<T, E> {}
// ...

impl<T: CloneFromCell> Cell<T> {
    pub fn get_cloned(&self) -> Self;
}
Steps / History

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

Unresolved Questions

cc @rust-lang/libs-api @rust-lang/lang

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the tracking issue, the Cell::get_cloned API sketch, and implementation PR 145685. Read the linked libs-team discussion and unresolved questions before making changes, especially the proposed method location and soundness requirements. Done means the implementation, final comment period, and stabilization PR have been completed.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.