Skip to content

CopyCell::set has undefined behavior #5

Description

@SimonSapin

toolshed/src/cell.rs

Lines 10 to 12 in e42cd8c

pub struct CopyCell<T> {
/// Internal value
value: T,

toolshed/src/cell.rs

Lines 61 to 68 in e42cd8c

pub fn set(&self, value: T) {
use std::ptr::write_volatile;
// Regular write produces abnormal behavior when running tests in
// `--release` mode. Reordering writes when the compiler assumes
// things are immutable is dangerous.
unsafe { write_volatile(self.mut_ptr(), value) };
}

This is writing through &T without std::cell::UnsafeCell being involved at all. Unfortunately UnsafeCell is currently not Copy, so as far as I understand CopyCell cannot be made sound until something like rust-lang/rust#55207 is implemented.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions