-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cell
should be Copy
#20813
Comments
I think let x = Cell::new(1);
Thread::scoped(move || {
x.set(2);
}).join();
println!("{}", x.get()); won't do what one might be hoping. |
The lack of a |
@huonw I would rather not use |
Does the same rationale from #20199 (comment) apply here? |
Yeah, I think we've settled on a "tricky things shouldn't be Copy" convention here. It's back-compat to add later, and right now the consequences are troubling. |
I don't see what's "troubling" about the consequences here, can someone clarify? The only substantive thing I've heard is the concern that someone might accidentally not share memory, which can already happen with any other |
I don't personally have a huge opinion (other than the back-compat consideration), but It seems like this, and the considerations in #20199 (same thing applying to RNGs), would be entirely resolved by a extra trait, say (The complexity may not be worth it.) |
Sure, we could abbreviate |
Whoops, sorry I keep ADD'ing away every time I start writing a comment here. You know, like, re-installing my entire OS. 🐫 Basically what @huonw said. In my mind Cell is basically a container or smaht-pointer type. It's not really "plain old data" (it contains an UnsafeCell!). But mostly I think we just want to be conservative here. |
But it is safe, regardless of how it exists in your, my, or anyone's mind. It's only ever allowed to contain plain old data. The fact that it contains Your |
CC @pcwalton (you're captain OIBIT, right?) |
I think this can be a general "what to do about iffy cases and Cell" meta-issue. Tracking it on multiple issues doesn't seem super helpful at this point. |
This should be reopened. There are legitimate uses of I apologize, I know this is a pretty old issue, but the current behavior is surprising. At the very least |
I think making |
I'm not really sure why it isn't. It can only ever hold
Copy
data andCell::new(some_cell.get())
has the same effect as a memcpy, so the effect of not making itCopy
is mostly to just make it annoying to use types withCell
s in them (since you can't#[derive(Copy)]
on them, use them with the[Foo ; n]
instantiation syntax in fixed-size arrays, put them in otherCell
s, etc.).The text was updated successfully, but these errors were encountered: