Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4305769
Tweak handling of "struct like start" where a struct isn't supported
estebank Sep 24, 2025
a4e87e9
Support `#[rustc_align_static]` inside `thread_local!`
Jules-Bertholet Sep 10, 2025
bb48c16
Simplify logic slightly
estebank Sep 24, 2025
4d32b9a
Hoist non-platform-specific code out of `thread_local_inner!`
Jules-Bertholet Sep 27, 2025
86f2d42
indexing: reword help
hkBst Sep 15, 2025
5b809b3
Don't enable shared memory with Wasm atomics
daxpedda Oct 1, 2025
8dfea22
implement `Box::take`
edwloef Oct 1, 2025
6961953
Switch `citool` to 2024 edition
GuillaumeGomez Oct 1, 2025
4baf920
Initialize llvm submodule if not already the case to run citool
GuillaumeGomez Oct 1, 2025
3e8ce2b
Adjust WASI and WALI targets
daxpedda Oct 1, 2025
94f00f4
Fix memory leak in `os` impl
Jules-Bertholet Oct 1, 2025
5991c87
Update books
rustbot Oct 1, 2025
30d57ab
mbe: Rename a local variable to match corresponding field names
joshtriplett Sep 14, 2025
6bff1ab
mbe: Support `unsafe` attribute rules
joshtriplett Sep 14, 2025
05c5b87
mbe: Add parsing tests for `unsafe` macro rules
joshtriplett Sep 14, 2025
ea0e00c
mbe: Add tests for `unsafe` attr invocation
joshtriplett Sep 14, 2025
4fc0a0d
mbe: `expand_invoc`: Add comment about not needing to check safety of…
joshtriplett Sep 28, 2025
59c4dfe
Forbid `//@ compile-flags: -Cincremental=` in tests
Zalathar Oct 1, 2025
92aac1b
Rollup merge of #146281 - Jules-Bertholet:static-align-thread-local, …
matthiaskrgr Oct 2, 2025
ac7beab
Rollup merge of #146535 - joshtriplett:mbe-unsafe-attr, r=petrochenkov
matthiaskrgr Oct 2, 2025
7320d3e
Rollup merge of #146585 - hkBst:indexing-1, r=jdonszelmann
matthiaskrgr Oct 2, 2025
e041b2c
Rollup merge of #147004 - estebank:ascription-in-pat, r=fee1-dead
matthiaskrgr Oct 2, 2025
b78b107
Rollup merge of #147221 - Zalathar:incremental, r=lqd
matthiaskrgr Oct 2, 2025
8a18176
Rollup merge of #147225 - daxpedda:wasm-u-u-atomics-threads, r=alexcr…
matthiaskrgr Oct 2, 2025
fbe6834
Rollup merge of #147227 - edwloef:box_take, r=joboet
matthiaskrgr Oct 2, 2025
f4dcfa6
Rollup merge of #147233 - GuillaumeGomez:citool-submodule-init, r=Kobzol
matthiaskrgr Oct 2, 2025
2d1efe7
Rollup merge of #147236 - rustbot:docs-update, r=ehuss
matthiaskrgr Oct 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement Box::take
  • Loading branch information
edwloef committed Oct 1, 2025
commit 8dfea22c974fe18aca8322f1c73f8455dc42c66f
31 changes: 31 additions & 0 deletions library/alloc/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,37 @@ impl<T, A: Allocator> Box<T, A> {
pub fn into_inner(boxed: Self) -> T {
*boxed
}

/// Consumes the `Box` without consuming its allocation, returning the wrapped value and a `Box`
/// to the uninitialized memory where the wrapped value used to live.
///
/// This can be used together with [`write`](Box::write) to reuse the allocation for multiple
/// boxed values.
///
/// # Examples
///
/// ```
/// #![feature(box_take)]
///
/// let c = Box::new(5);
///
/// // take the value out of the box
/// let (value, uninit) = Box::take(c);
/// assert_eq!(value, 5);
///
/// // reuse the box for a second value
/// let c = Box::write(uninit, 6);
/// assert_eq!(*c, 6);
/// ```
#[unstable(feature = "box_take", issue = "147212")]
pub fn take(boxed: Self) -> (T, Box<mem::MaybeUninit<T>, A>) {
unsafe {
let (raw, alloc) = Box::into_raw_with_allocator(boxed);
let value = raw.read();
let uninit = Box::from_raw_in(raw.cast::<mem::MaybeUninit<T>>(), alloc);
(value, uninit)
}
}
}

impl<T> Box<[T]> {
Expand Down
Loading