Tracking Issue for `Vec::recycle`
Open
@GrigorenkoPV is already working on this.
Since Oct 31, 2025.
C-tracking-issue
T-libs
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Feature gate: #![feature(vec_recycle)]
This is a tracking issue for the Vec::recycle method, which allows reusing a Vec in a loop even if the lifetime unification would otherwise disallow it.
Public API
// in alloc::vec
#![feature(transmutability)]
#![feature(trait_alias)]
use std::mem::{Assume, MaybeUninit, TransmuteFrom};
/// Implemented if the size and alignment `T` and `Self` are both equal.
trait Recyclable<T> =
for<'a> TransmuteFrom<&'a MaybeUninit<T>, { Assume::SAFETY }>
where
T: for<'a> TransmuteFrom<&'a MaybeUninit<Self>, { Assume::SAFETY }>;
impl<T> Vec<T> {
#[feature(vec_recycle)]
pub fn recycle<U>(self) -> Vec<U> where U: Recyclable<T>;
}
Steps / History
- ACP: rust-lang/libs-team#674
- Implementation: #...
- Final comment period (FCP)^1
- Stabilization PR
Unresolved Questions
- Make sure that we don't unintentionally create reliance on this as workaround for lack of stable TransmuteFrom, when this stabilizes.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.