Skip to content

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

@FeldrinH

Description

@FeldrinH

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-libsRelevant to the library team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions