rust-lang / rust-lang/rust

Request for documentation: Is it safe to mutate contents of `Cell<T>` through `as_ptr`?

Open
#149,564 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-docs T-libs T-opsem
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Location (URL)

https://doc.rust-lang.org/std/cell/struct.Cell.html#method.as_ptr

Summary

Cell<T>::as_ptr allows you to obtain a pointer to T. This pointer can in theory be used to modify the contents of the cell, but is this sound? If I use ptr::write to write to the value, is that sound? Similarly, if I cast the pointer to &mut T and use that to modify the contents, is that sound (assuming I don't use set or get on the original cell while the mutable reference exists)?

I think answers to these questions should be present in the documentation of Cell<T>::as_ptr, otherwise it is unclear what the returned pointer allows.

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 at the documented Cell::as_ptr entry point linked in the issue, then review the surrounding Cell documentation and the stated pointer-use questions. The documentation work is done when it clearly explains whether ptr::write and casting the pointer to &mut T are sound under the conditions described.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.