RS.CLIPPY.UNSOUND_COLLECTION_TRANSMUTE
Transmute between collections of layout-incompatible types
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: unsound_collection_transmute. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for transmutes between collections whose types have different ABI, size or alignment.
Why is this bad?
This is undefined behavior.
Known problems
Currently, we cannot know whether a type is a
collection, so we just lint the ones that come with std.
Example
// different size, therefore likely out-of-bounds memory access
// You absolutely do not want this in your code!
unsafe {
std::mem::transmute::<_, Vec<u32>>(vec![2_u16])
};
You must always iterate, map and collect the values:
vec![2_u16].into_iter().map(u32::from).collect::<Vec<_>>();