Skip to content

RevSlice requires repr(C) or repr(transparent) #1

@dtolnay

Description

@dtolnay

Without one of those attributes, my understanding is the transmute from &[T] to &RevSlice<T> is undefined behavior. The compiler is free to stick some additional data at the start of RevSlice<T> or give it a stricter alignment than [T]. For example some targets may require all struct types to have some minimum alignment that is not required for slices.

From nomicon's Alternative representations:

#[repr(C)] is also necessary to soundly do more elaborate tricks with data layout such as reinterpreting values as a different type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions