Uh oh!
There was an error while loading. Please reload this page.
Add Box::into_inner. - #80438
Conversation
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
sugar700
commented
Dec 28, 2020
Personally I would rather prefer to have |
158ddc3 to
6876373Comparefmease
commented
Dec 28, 2020
Should the documentation mention deref'ing the box as an alternative? This might prevent confusion. |
Uh oh!
There was an error while loading. Please reload this page.
m-ou-se
commented
Dec 30, 2020
That's a rather large change; one that should be discussed with the lang team first. Has there been any discussion on this? How about alternatives like a moving-out-of-deref trait as suggested above? Without that language change, is there a good use case for this new function? |
crlf0710
commented
Dec 31, 2020
@m-ou-se Yes, there is still a use case (which i think is good). #[derive(Copy,Clone,Debug)]structS;let boxed_val = Box::new(S);let val = *boxed_val;// this copies the value out (with Deref), but the memory is not deallocated.println!("{:?}", boxed_val);//it's still alive now, needs another `drop` to deallocate.// do something more.This seems a footgun because the behavior of that line depends on whether S is
Indeed! But i think whether or not that change will happen, this convenience function serves its purpose well. And there's already |
JohnCSimon
commented
Feb 7, 2021
merge conflict |
Uh oh!
There was an error while loading. Please reload this page.
crlf0710
commented
Feb 9, 2021
Rebased and squashed. |
| /// | ||
| /// let c = Box::new(5); | ||
| /// | ||
| /// assert_eq!(Box::into_inner(c), 5); |
There was a problem hiding this comment.
Isn't this the same as *c? Why is the deref bad and we want to remove it?
There was a problem hiding this comment.
This was already discussed. See the conversation above.
m-ou-se
commented
Feb 9, 2021
@bors r+ rollup |
bors
commented
Feb 9, 2021
📌 Commit ce7de07 has been approved by |
Rollup of 11 pull requests Successful merges: - rust-lang#79849 (Clarify docs regarding sleep of zero duration) - rust-lang#80438 (Add `Box::into_inner`.) - rust-lang#81466 (Add suggest mut method for loop) - rust-lang#81687 (Make Vec::split_at_spare_mut public) - rust-lang#81904 (Bump stabilization version for const int methods) - rust-lang#81909 ([compiler/rustc_typeck/src/check/expr.rs] Remove unnecessary refs in pattern matching) - rust-lang#81910 (Use format string in bootstrap panic instead of a string directly) - rust-lang#81913 (Rename HIR UnOp variants) - rust-lang#81925 (Add long explanation for E0547) - rust-lang#81926 (add suggestion to use the `async_recursion` crate) - rust-lang#81951 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This adds a
Box::into_innermethod to theBoxtype.I actually suggest deprecating the compiler magic of*bif this gets stablized in the future.r? @m-ou-se