You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.traitRecyclable<T> =
for<'a> TransmuteFrom<&'aMaybeUninit<T>,{Assume::SAFETY}>whereT:for<'a> TransmuteFrom<&'aMaybeUninit<Self>,{Assume::SAFETY}>;impl<T>Vec<T>{#[feature(vec_recycle)]pubfnrecycle<U>(self) -> Vec<U>whereU:Recyclable<T>;}
When uncommenting the two lines, the latest nightly (2025-10-30) gives the following errors:
error[E0277]: `[&[u8]]` cannot be safely transmuted into `[u8]`
--> src/main.rs:15:23
|
15 | check::<&[&[u8]], &[u8]>();
| ^^^^^ analyzing the transmutability of `[&[u8]]` is not yet supported
|
error[E0277]: `&[u8]` cannot be safely transmuted into `&[&[u8]]`
--> src/main.rs:16:20
|
16 | check::<&[u8], &[&[u8]]>();
| ^^^^^^^^ the minimum alignment of `&[u8]` (1) should be greater than that of `&[&[u8]]` (8)
|
So in one direction it's unimplemented and in the other direction it's seemingly wrong? Maybe i don't understand what it means by "minimum alignment", but the align_of gives the same values for both types.
@GrigorenkoPV Feel free to tag me in any TransmuteFrom issues! The second error is downstream of the first one, I think. We don't yet support analyzing the transmutability of slices, because we haven't decided on how to incorporate the fact we can't analyze the metadata component statically. (Relatedly, we also don't support analyzing trait objects yet.) TransmuteFrom will let you proof-of-concept a trait bound for 'easy' types, but we'll need to be a little more sophisticated for more unusual types.
Use the TransmuteFrom-based Recyclable for now, and I'll see this week if I can whip up an intrinsic Recyclable trait that skips the validity checks that are unnecessary for this use-case.
Activity
GrigorenkoPV commentedon Oct 31, 2025
@rustbot claim
(implementation)
GrigorenkoPV commentedon Oct 31, 2025
Unfortunately, there are some issues with the
TransmuteFromapproach.When uncommenting the two lines, the latest nightly (2025-10-30) gives the following errors:
So in one direction it's unimplemented and in the other direction it's seemingly wrong? Maybe i don't understand what it means by "minimum alignment", but the
align_ofgives the same values for both types.jswrenn commentedon Nov 2, 2025
@GrigorenkoPV Feel free to tag me in any
TransmuteFromissues! The second error is downstream of the first one, I think. We don't yet support analyzing the transmutability of slices, because we haven't decided on how to incorporate the fact we can't analyze the metadata component statically. (Relatedly, we also don't support analyzing trait objects yet.)TransmuteFromwill let you proof-of-concept a trait bound for 'easy' types, but we'll need to be a little more sophisticated for more unusual types.Use the
TransmuteFrom-basedRecyclablefor now, and I'll see this week if I can whip up an intrinsicRecyclabletrait that skips the validity checks that are unnecessary for this use-case.Rollup merge of rust-lang#148416 - GrigorenkoPV:vec_recycle, r=Mark-S…
Rollup merge of rust-lang#148416 - GrigorenkoPV:vec_recycle, r=Mark-S…
Unrolled build for #148416
Rollup merge of rust-lang#148416 - GrigorenkoPV:vec_recycle, r=Mark-S…