Skip to content
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

alloc: Make deriving more friendly with Arc #18127

Merged
merged 1 commit into from Oct 28, 2014

Conversation

alexcrichton
Copy link
Member

This adds impls of Eq/Ord/PartialEq/PartialOrd/Show/Default to Arc, and it
also removes the Send + Sync bound on the Clone impl of Arc to make it more
deriving-friendly. The Send + Sync requirement is still enforce on
construction, of course!

@rust-highfive
Copy link
Collaborator

warning Warning warning

  • These commits modify unsafe code. Please review it carefully!

@gereeter
Copy link
Contributor

Is the Send + Sync bound on construction just there so that people use Rc for non-threadsafe data? It feels to me that this should be documented or the bound should be removed.

@alexcrichton
Copy link
Member Author

Hm, it took me a second to think about this.

If you remove Send + Sync from all bounds, then it's safe to create Arc<Cell<int>> and share it among threads. Each instance of Arc<T> will be Send so long as T is Send (which Cell<int> is), but being this means that T needs to adhere to Sync if T is Send.

I think that we may be able to remove the Send bounds, but we may not be able to remove the Sync bounds.

I do agree, however, that the documentation of Arc could use some improvement!

@gereeter
Copy link
Contributor

I would think that Arc<T> would only be Send if T was Send + Sync, which would fix the problem.

@alexcrichton
Copy link
Member Author

I think we may be able to expose that with opt-in-builtin-traits, but until that time I'm not sure it's expressible. (but it'd be nice!)

This adds impls of Eq/Ord/PartialEq/PartialOrd/Show/Default to Arc<T>, and it
also removes the `Send + Sync` bound on the `Clone` impl of Arc to make it more
deriving-friendly. The `Send + Sync` requirement is still enforce on
construction, of course!
bors added a commit that referenced this pull request Oct 28, 2014
This adds impls of Eq/Ord/PartialEq/PartialOrd/Show/Default to Arc<T>, and it
also removes the `Send + Sync` bound on the `Clone` impl of Arc to make it more
deriving-friendly. The `Send + Sync` requirement is still enforce on
construction, of course!
@bors bors closed this Oct 28, 2014
@bors bors merged commit 35ad00d into rust-lang:master Oct 28, 2014
@alexcrichton alexcrichton deleted the deriving-arc branch November 20, 2014 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants