Skip to content

Is it sound to field-project into a Cell or UnsafeCell? #451

@joshlf

Description

@joshlf

Given a &Cell<T> or &UnsafeCell<T>, is it sound to produce a &Cell<F> or &UnsafeCell<F> to a field within the original (assuming that lifetimes are respected etc etc)? E.g.:

pub fn project(cell: &Cell<(u8, u16)>) -> &Cell<u16> {
    let cell_raw: *const _ = cell;
    let inner_raw: *const (u8, u16) = cell_raw.cast();
    let field_raw = core::mem::addr_of!(inner_raw.1);
    unsafe { &*field_raw }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions