Skip to content

Interior mutable shared ref to constant memory is UB even when not writing #246

Closed
@RalfJung

Description

@RalfJung

Current Stacked Borrows makes this UB:

fn main() { unsafe {
    let x = &0usize;
    let y: &std::cell::Cell<usize> = std::mem::transmute(x);
} }

To be honest I do not think there is a good reason for this. We cannot optimize much around interior mutable types, so I don't think we should require them to be writable unless we are actually mutating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)C-open-questionCategory: An open question that we should revisit

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions