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

Zero-initialize vec![None; n] for Option<&T>, Option<&mut T> and Option<Box<T>> #64893

Merged
merged 1 commit into from
Oct 1, 2019

Conversation

SimonSapin
Copy link
Contributor

No description provided.

@rust-highfive
Copy link
Collaborator

r? @sfackler

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 29, 2019
@@ -1748,6 +1748,31 @@ unsafe impl<T: ?Sized> IsZero for *mut T {
}
}

// `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
// For fat pointers, the bytes that would be the pointer metadata in the `Some` variant
// are padding in the `None` variant, so ignoring them and zero-initializing instead is ok.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CC #64891

@Centril
Copy link
Contributor

Centril commented Sep 29, 2019

r? @RalfJung

@rust-highfive rust-highfive assigned RalfJung and unassigned sfackler Sep 29, 2019
@SimonSapin
Copy link
Contributor Author

r? @sfackler
(Picking someone else per #64891 (comment))

@rust-highfive rust-highfive assigned sfackler and unassigned RalfJung Sep 29, 2019
@sfackler
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 29, 2019

📌 Commit 6c01c0e has been approved by sfackler

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 29, 2019
tmandry added a commit to tmandry/rust that referenced this pull request Sep 30, 2019
…ckler

Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>`
tmandry added a commit to tmandry/rust that referenced this pull request Sep 30, 2019
…ckler

Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>`
bors added a commit that referenced this pull request Oct 1, 2019
Rollup of 9 pull requests

Successful merges:

 - #64377 (Add long error explanation for E0493)
 - #64786 (Use https for curl when building for linux)
 - #64828 (Graphviz debug output for generic dataflow analysis)
 - #64838 (Add long error explanation for E0550)
 - #64891 (Fix `vec![x; n]` with null raw fat pointer zeroing the pointer metadata)
 - #64893 (Zero-initialize `vec![None; n]` for `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>`)
 - #64911 (Fixed a misleading documentation issue #64844)
 - #64921 (Add test for issue-64662)
 - #64923 (Add missing links for mem::needs_drop)

Failed merges:

 - #64918 (Add long error explanation for E0551)

r? @ghost
@bors bors merged commit 6c01c0e into rust-lang:master Oct 1, 2019
@SimonSapin SimonSapin deleted the vec-of-option-box branch November 28, 2019 12:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants