Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add raw ptr variant of UnsafeCell::get #66248

Merged
merged 5 commits into from Nov 13, 2019

Conversation

@RalfJung
Copy link
Member

RalfJung commented Nov 9, 2019

This has come up recently in #66051 (Cc @Centril @pitdicker) as well as in discussion with @nikomatsakis and in unrelated discussion with @withoutboats.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 9, 2019

r? @sfackler

(rust_highfive has picked a reviewer for you, use r? to override)

@RalfJung

This comment has been minimized.

Copy link
Member Author

RalfJung commented Nov 9, 2019

Also Cc @SimonSapin because of the relation to MaybeUninit -- this is needed for gradual initialization of an UnsafeCell.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Nov 9, 2019

As the code comment notes, this can be a simple pointer case because of #[repr(transparent)]. Which means that this can be implemented outside of the standard library, so perhaps having it inside is less pressing?

So I suppose the question is: is it easier for users to find a method than to figure out that a pointer cast is the way to go? Even if we have documentation (perhaps on MaybeUninit) that recommends a cast?

@RalfJung

This comment has been minimized.

Copy link
Member Author

RalfJung commented Nov 9, 2019

Which means that this can be implemented outside of the standard library, so perhaps having it inside is less pressing?

get can also be implemented outside the standard library with the same argument. But right now we say that get is the only way to actually correctly get a mutable pointer to the inside; using a cast is forbidden.

IOW, this is a case of libstd using its special status.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Nov 9, 2019

Good points. r=me with:

  • A tracking issue
  • Maybe mention in the doc-comment that this differs from get in accepting a raw pointer? It’s visible in the signature, but it doesn’t hurt repeating.
@the8472

This comment has been minimized.

Copy link

the8472 commented Nov 9, 2019

  • Maybe mention in the doc-comment that this differs from get in accepting a raw pointer? It’s visible in the signature, but it doesn’t hurt repeating.

Also why one may want to use it over get (the dereferencable/valid data rules)

src/libcore/cell.rs Outdated Show resolved Hide resolved
src/libcore/cell.rs Outdated Show resolved Hide resolved
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
@RalfJung RalfJung mentioned this pull request Nov 13, 2019
0 of 1 task complete
@RalfJung

This comment has been minimized.

Copy link
Member Author

RalfJung commented Nov 13, 2019

@SimonSapin @the8472 I expanded the docs, please check.

@SimonSapin

This comment has been minimized.

Copy link
Contributor

SimonSapin commented Nov 13, 2019

Docs look good. r=me, pending the method receiver type discussion above.

@RalfJung

This comment has been minimized.

Copy link
Member Author

RalfJung commented Nov 13, 2019

@bors r=SimonSapin

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 13, 2019

📌 Commit 861698a has been approved by SimonSapin

JohnTitor added a commit to JohnTitor/rust that referenced this pull request Nov 13, 2019
…onSapin

add raw ptr variant of UnsafeCell::get

This has come up recently in rust-lang#66051 (Cc @Centril @pitdicker) as well as in discussion with @nikomatsakis and in unrelated discussion with @withoutboats.
bors added a commit that referenced this pull request Nov 13, 2019
Rollup of 16 pull requests

Successful merges:

 - #65821 (Use `drop_in_place` in `array::IntoIter::drop`)
 - #65932 (download .tar.xz if python3 is used)
 - #66074 ([mir-opt] Turn on the `ConstProp` pass by default)
 - #66094 (Fix documentation for `Iterator::count()`.)
 - #66166 (rename cfg(rustdoc) into cfg(doc))
 - #66186 (Add long error explanation for E0623)
 - #66227 (docs: Fix link to BufWriter::flush)
 - #66248 (add raw ptr variant of UnsafeCell::get)
 - #66292 (add Result::map_or)
 - #66297 (Add a callback that allows compiler consumers to override queries.)
 - #66317 (Use a relative bindir for rustdoc to find rustc)
 - #66330 (Improve non-exhaustiveness handling in usefulness checking)
 - #66331 (Add some tests for fixed ICEs)
 - #66334 (Move Session fields to CrateStore)
 - #66335 (Move self-profile infrastructure to data structures)
 - #66337 (Remove dead code for encoding/decoding lint IDs)

Failed merges:

r? @ghost
JohnTitor added a commit to JohnTitor/rust that referenced this pull request Nov 13, 2019
…onSapin

add raw ptr variant of UnsafeCell::get

This has come up recently in rust-lang#66051 (Cc @Centril @pitdicker) as well as in discussion with @nikomatsakis and in unrelated discussion with @withoutboats.
bors added a commit that referenced this pull request Nov 13, 2019
Rollup of 14 pull requests

Successful merges:

 - #65932 (download .tar.xz if python3 is used)
 - #66094 (Fix documentation for `Iterator::count()`.)
 - #66166 (rename cfg(rustdoc) into cfg(doc))
 - #66186 (Add long error explanation for E0623)
 - #66227 (docs: Fix link to BufWriter::flush)
 - #66248 (add raw ptr variant of UnsafeCell::get)
 - #66292 (add Result::map_or)
 - #66297 (Add a callback that allows compiler consumers to override queries.)
 - #66317 (Use a relative bindir for rustdoc to find rustc)
 - #66330 (Improve non-exhaustiveness handling in usefulness checking)
 - #66331 (Add some tests for fixed ICEs)
 - #66334 (Move Session fields to CrateStore)
 - #66335 (Move self-profile infrastructure to data structures)
 - #66337 (Remove dead code for encoding/decoding lint IDs)

Failed merges:

r? @ghost
@bors bors merged commit 861698a into rust-lang:master Nov 13, 2019
4 checks passed
4 checks passed
pr Build #20191113.13 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (Linux x86_64-gnu-tools) Linux x86_64-gnu-tools succeeded
Details
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 13, 2019

☔️ The latest upstream changes (presumably #66366) made this pull request unmergeable. Please resolve the merge conflicts.

@RalfJung RalfJung deleted the RalfJung:unsafe_cell_raw_get branch Nov 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.