Help with miri error
⚓ Rust 📅 2025-09-25 👤 surdeus 👁️ 6Hi.
I want to transmute &[u8] to &A where A is a DST and just lays out some fixed prefix of the original slice:
/// `T` here is for `CoerceUnsized`
struct A<T: ?Sized = [u8]> {
    prefix: [u8; 2],
    tail: T,
}
My approach was quite strait forward — inspecting the pointer data of identical *const [u8] and *const A I realized that the *const A have it's length smaller by the length of the prefix field,
so to transmute &[u8] to &A I did the same — made slice length smaller by the length of the prefix and called transmute.
Some basic assertions shows that the resulting &A does indeed represents the original &[u8], but miri complains with "Undefined Behavior: trying to retag ..." (see the full error by invoking miri on playground).
The error seem cryptic to me. Is it actually UB to transmute?
1 post - 1 participant
🏷️ Rust_feed