-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Add unstable Share trait #156828
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
Merged
Merged
Add unstable Share trait #156828
Changes from 12 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
1521455
Add share_trait feature gate
P8L1 e5a6796
Add unstable Share trait
P8L1 02109ee
Implement Share for shared references
P8L1 d082ac9
Tighten initial Share trait implementation
P8L1 fc33b6d
Add Share impl for Rc
P8L1 78b0f9d
Add Share impl for Arc
P8L1 4b32cb2
Add Share impl for mpsc Sender
P8L1 4a32c28
Add Share impl for mpsc SyncSender
P8L1 71bcc49
Update Share non-implementor diagnostics
P8L1 9b3cd57
Remove provisional Share trait FIXME notes
P8L1 c01e320
Document unstable Share trait semantics
P8L1 501ab4e
Clarify Share trait docs
P8L1 2f953da
Remove unnecessary Share feature gate plumbing
P8L1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| //@ check-pass | ||
|
|
||
| #![feature(share_trait)] | ||
|
|
||
| fn main() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| //@ run-pass | ||
|
|
||
| #![feature(share_trait)] | ||
|
|
||
| use std::clone::Share; | ||
| use std::sync::{Arc, Mutex}; | ||
|
|
||
| trait Value { | ||
| fn get(&self) -> i32; | ||
| } | ||
|
|
||
| impl Value for Mutex<i32> { | ||
| fn get(&self) -> i32 { | ||
| *self.lock().unwrap() | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| let value = Arc::new(Mutex::new(1)); | ||
| let shared = value.share(); | ||
|
|
||
| assert!(Arc::ptr_eq(&value, &shared)); | ||
| *shared.lock().unwrap() = 2; | ||
| assert_eq!(*value.lock().unwrap(), 2); | ||
|
|
||
| let dyn_value: Arc<dyn Value + Send + Sync> = Arc::new(Mutex::new(3)); | ||
| let shared_dyn_value = dyn_value.share(); | ||
|
|
||
| assert!(Arc::ptr_eq(&dyn_value, &shared_dyn_value)); | ||
| assert_eq!(shared_dyn_value.get(), 3); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //@ run-pass | ||
|
|
||
| #![feature(share_trait)] | ||
|
|
||
| use std::clone::Share; | ||
| use std::sync::mpsc::channel; | ||
|
|
||
| fn main() { | ||
| let (sender, receiver) = channel(); | ||
| let shared_sender = sender.share(); | ||
|
|
||
| sender.send(1).unwrap(); | ||
| shared_sender.send(2).unwrap(); | ||
|
|
||
| let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()]; | ||
| received.sort(); | ||
|
|
||
| assert_eq!(received, [1, 2]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| //@ run-pass | ||
|
|
||
| #![feature(share_trait)] | ||
|
|
||
| use std::clone::Share; | ||
| use std::sync::mpsc::sync_channel; | ||
|
|
||
| fn main() { | ||
| let (sender, receiver) = sync_channel(2); | ||
| let shared_sender = sender.share(); | ||
|
|
||
| sender.send(1).unwrap(); | ||
| shared_sender.send(2).unwrap(); | ||
|
|
||
| let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()]; | ||
| received.sort(); | ||
|
|
||
| assert_eq!(received, [1, 2]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| use std::clone::Share; | ||
| //~^ ERROR use of unstable library feature `share_trait` | ||
|
|
||
| #[derive(Clone)] | ||
| struct Alias; | ||
|
|
||
| impl Share for Alias {} | ||
| //~^ ERROR use of unstable library feature `share_trait` | ||
|
|
||
| fn share_generic<T: Share>(value: &T) -> T { | ||
| //~^ ERROR use of unstable library feature `share_trait` | ||
| value.share() | ||
| //~^ ERROR use of unstable library feature `share_trait` | ||
| } | ||
|
|
||
| fn main() { | ||
| let value = Alias; | ||
| let _ = Share::share(&value); | ||
| //~^ ERROR use of unstable library feature `share_trait` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| error[E0658]: use of unstable library feature `share_trait` | ||
| --> $DIR/share-trait-no-feature.rs:1:5 | ||
| | | ||
| LL | use std::clone::Share; | ||
| | ^^^^^^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `share_trait` | ||
| --> $DIR/share-trait-no-feature.rs:7:6 | ||
| | | ||
| LL | impl Share for Alias {} | ||
| | ^^^^^ | ||
| | | ||
| = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `share_trait` | ||
| --> $DIR/share-trait-no-feature.rs:10:21 | ||
| | | ||
| LL | fn share_generic<T: Share>(value: &T) -> T { | ||
| | ^^^^^ | ||
| | | ||
| = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `share_trait` | ||
| --> $DIR/share-trait-no-feature.rs:18:13 | ||
| | | ||
| LL | let _ = Share::share(&value); | ||
| | ^^^^^^^^^^^^ | ||
| | | ||
| = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0658]: use of unstable library feature `share_trait` | ||
| --> $DIR/share-trait-no-feature.rs:12:11 | ||
| | | ||
| LL | value.share() | ||
| | ^^^^^ | ||
| | | ||
| = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error: aborting due to 5 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0658`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #![feature(share_trait)] | ||
|
|
||
| use std::clone::Share; | ||
|
|
||
| fn require_share<T: Share>() {} | ||
|
|
||
| fn main() { | ||
| require_share::<&mut i32>(); | ||
| //~^ ERROR the trait bound `&mut i32: Share` is not satisfied | ||
|
|
||
| require_share::<String>(); | ||
| //~^ ERROR the trait bound `String: Share` is not satisfied | ||
|
|
||
| require_share::<Vec<i32>>(); | ||
| //~^ ERROR the trait bound `Vec<i32>: Share` is not satisfied | ||
|
|
||
| require_share::<Box<i32>>(); | ||
| //~^ ERROR the trait bound `Box<i32>: Share` is not satisfied | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.