Skip to content

The Cell type may be unsound as it is currently implemented #10231

Closed
@alexcrichton

Description

@alexcrichton
use std::cell::Cell;

struct A;

impl A {
    fn id<'a>(&'a mut self) -> &'a mut A { self }

    fn bar(&mut self) {
        println!("oh no!");
    }
}

fn foo(f: &fn()) { f() }

fn main() {
    let c = Cell::new_empty();
    let mut a = A;
    let d = Cell::new(&mut a);
    do d.with_mut_ref |this| {
        c.put_back(this.id());
    }
    do d.with_mut_ref |this1| {
        do c.with_mut_ref |this2| {
            this1.bar();
            this2.bar();
        }
    }
}

Near the end this and this2 are two mutable pointers to the same object, which I believe is unsound.

Nominating, this is not good.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions