rust-lang / rust-lang/rust

Tracking Issue for `Vec::recycle`

Open
#148,227 3 comments 3 reactions 1 assignee View on GitHub

@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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.