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

cast the entire slice to a raw pointer, not just the first element #80

Merged
merged 1 commit into from
May 28, 2019

Conversation

RalfJung
Copy link
Member

A strict reading of pointer provenance implies that when a &T gets cast to *const T, you may only use the raw pointer to access that T, not its neighbors. That's what Miri currently implements, though it is less strict around statics (which is why this one does not currently cause a Miri failure -- I'd like to make Miri more strict though).

Cc rust-lang/unsafe-code-guidelines#134

@@ -357,7 +357,8 @@ impl<T> RawTable<T> {
pub fn new() -> Self {
Self {
data: NonNull::dangling(),
ctrl: NonNull::from(&Group::static_empty()[0]),
// Be careful to cast the entire slice to a raw pointer.
ctrl: unsafe { NonNull::new_unchecked(Group::static_empty().as_ptr() as *mut u8) },
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, the mut cast here is actually meaningful -- the rest of the code must be careful not to write to this! But I suppose that's already the case, this is a shared global static after all.

@Amanieu
Copy link
Member

Amanieu commented May 28, 2019

@bors r+

@bors
Copy link
Contributor

bors commented May 28, 2019

📌 Commit 2693d12 has been approved by Amanieu

@bors
Copy link
Contributor

bors commented May 28, 2019

⌛ Testing commit 2693d12 with merge c765ea0...

bors added a commit that referenced this pull request May 28, 2019
cast the entire slice to a raw pointer, not just the first element

A strict reading of pointer provenance implies that when a `&T` gets cast to `*const T`, you may only use the raw pointer to access that `T`, not its neighbors.  That's what Miri currently implements, though it is less strict around statics (which is why this one does not currently cause a Miri failure -- I'd like to make Miri more strict though).

Cc rust-lang/unsafe-code-guidelines#134
@bors
Copy link
Contributor

bors commented May 28, 2019

☀️ Test successful - checks-travis
Approved by: Amanieu
Pushing c765ea0 to master...

@bors bors merged commit 2693d12 into rust-lang:master May 28, 2019
@RalfJung
Copy link
Member Author

What is needed to get this updated in rustc?

@Amanieu
Copy link
Member

Amanieu commented May 28, 2019

I need to publish a new version of the crate and Cargo.lock needs to be updated in rustc.

@Amanieu
Copy link
Member

Amanieu commented May 30, 2019

I published v0.3.1 with this change.

@RalfJung
Copy link
Member Author

Thanks a lot!

Centril added a commit to Centril/rust that referenced this pull request May 30, 2019
bump hashbrown

Bump hashbrown to a version that includes rust-lang/hashbrown#80.
bors added a commit to rust-lang/rust that referenced this pull request Jun 1, 2019
@RalfJung RalfJung deleted the raw branch August 25, 2019 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants