Skip to content

Should a mutable reference which is only used for reads become invalid on reads through other ptrs? #351

Open
@RalfJung

Description

@RalfJung

Brought up by @saethlin around here: rust-lang/rust#92092 fixes a standard library issue where

there is a mutable reference which is used only for reads becomes invalid as a result of interior mutation of the referent, where a shared reference does not become invalid.

So, this is a case where using a shared ref rather than a mutable ref was more correct, in the face of mutation inside an UnsafeCell.

I have to say I consider this fully intended, the promise of a mutable reference is uniqueness and UnsafeCell deliberately has no effect on &mut. But it is worth tracking whether violating this rule is a common issue, and whether it might be worth somehow allowing this. The most extreme version of this would in general allow reads through other pointers when using an &mut (perhaps making the &mut read-only in the process? that would be a new mechanism in the aliasing model though). But that will severely impact our even entirely remove our ability to reorder writes to mutable references.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-SB-vs-TBTopic: Design questions where SB and TB are opposite sides of the design axisA-aliasing-modelTopic: Related to the aliasing model (e.g. Stacked/Tree Borrows)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions