-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement write() method for Box<MaybeUninit<T>> #88906
Conversation
r? @dtolnay (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
005cd4b
to
d0c2ccf
Compare
This comment has been minimized.
This comment has been minimized.
d0c2ccf
to
322b67d
Compare
This comment has been minimized.
This comment has been minimized.
322b67d
to
f747ae4
Compare
There's a pending RFC that proposes another approach which would probably make this one redundant. |
Ping from triage: |
Sure! This is waiting on reviewer. I believe this change is simple and obvious. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this change is simple and obvious.
To point out why this change isn't simple and obvious: this is a breaking change. It can make previously working code fail to compile, or keep compiling but do the wrong thing, or silently introduce UB into existing correct code.
Here is an example of an ordinary idiomatic use of MaybeUninit which would no longer work:
struct Thing {
buf: Box<MaybeUninit<[u8; N]>>,
}
impl Thing {
fn method(&mut self) {
let _arr = self.buf.write([0; N]);
}
}
Ah, I see, good point. I think changing it to |
☔ The latest upstream changes (presumably #91230) made this pull request unmergeable. Please resolve the merge conflicts. |
9bdca22
to
928a0b0
Compare
Fixed and rebased. Also noticed that wording in the example looked like a promise of optimization which is not actually guaranteed, so I reworded it accordingly. |
This comment has been minimized.
This comment has been minimized.
This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in rust-lang#63291 which this change extends.
928a0b0
to
41e21aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
@bors r+ |
📌 Commit 41e21aa has been approved by |
…tolnay Implement write() method for Box<MaybeUninit<T>> This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in rust-lang#63291 which this change extends.
…tolnay Implement write() method for Box<MaybeUninit<T>> This adds method similar to `MaybeUninit::write` main difference being it returns owned `Box`. This can be used to elide copy from stack safely, however it's not currently tested that the optimization actually occurs. Analogous methods are not provided for `Rc` and `Arc` as those need to handle the possibility of sharing. Some version of them may be added in the future. This was discussed in rust-lang#63291 which this change extends.
…askrgr Rollup of 10 pull requests Successful merges: - rust-lang#88906 (Implement write() method for Box<MaybeUninit<T>>) - rust-lang#90269 (Make `Option::expect` unstably const) - rust-lang#90854 (Type can be unsized and uninhabited) - rust-lang#91170 (rustdoc: preload fonts) - rust-lang#91273 (Fix ICE rust-lang#91268 by checking that the snippet ends with a `)`) - rust-lang#91381 (Android: -ldl must appear after -lgcc when linking) - rust-lang#91453 (Document Windows TLS drop behaviour) - rust-lang#91462 (Use try_normalize_erasing_regions in needs_drop) - rust-lang#91474 (suppress warning about set_errno being unused on DragonFly) - rust-lang#91483 (Sync rustfmt subtree) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
☔ The latest upstream changes (presumably #91486) made this pull request unmergeable. Please resolve the merge conflicts. |
I'm confused by this - it conflicted with an unmerged PR? Is this some fluke or am I actually supposed to do something (what?) about it? |
This has been merged into master by bors (in #91486), but GitHub didn't detect it for whatever reason. Closing. |
This adds method similar to
MaybeUninit::write
main difference beingit returns owned
Box
. This can be used to elide copy from stacksafely, however it's not currently tested that the optimization actually
occurs.
Analogous methods are not provided for
Rc
andArc
as those need tohandle the possibility of sharing. Some version of them may be added in
the future.
This was discussed in #63291 which this change extends.