Skip to content

Hard to find out whether a type is Send or Sync #44363

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

Closed
tirr-c opened this issue Sep 6, 2017 · 2 comments
Closed

Hard to find out whether a type is Send or Sync #44363

tirr-c opened this issue Sep 6, 2017 · 2 comments

Comments

@tirr-c
Copy link
Contributor

tirr-c commented Sep 6, 2017

Currently, only the explicit unsafe impls of Send and Sync (and their ! counterparts) are shown in the docs. This makes me write a test code that actually sends some value across thread boundaries. For example, to find out whether Core from tokio-core is Send, I should test it:

extern crate tokio_core;
extern crate futures;

fn main() {
    let core = tokio_core::reactor::Core::new().unwrap();
    std::thread::spawn(move || {
        let mut xcore = core;
        xcore.run(futures::future::ok::<usize, usize>(0)).unwrap();
    }).join().unwrap();
}

Then it turns out that Core does not implement Send. (And it's hard to get the point quickly.)

error[E0277]: the trait bound `std::rc::Rc<std::cell::RefCell<tokio_core::reactor::Inner>>: std::marker::Send` is not satisfied in `[closure@src/main.rs:6:24: 9:6 core:tokio_core::reactor::Core]`
 --> src/main.rs:6:5
  |
6 |     std::thread::spawn(move || {
  |     ^^^^^^^^^^^^^^^^^^ `std::rc::Rc<std::cell::RefCell<tokio_core::reactor::Inner>>` cannot be sent between threads safely
  |
  = help: within `[closure@src/main.rs:6:24: 9:6 core:tokio_core::reactor::Core]`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::RefCell<tokio_core::reactor::Inner>>`
  = note: required because it appears within the type `tokio_core::reactor::Core`
  = note: required because it appears within the type `[closure@src/main.rs:6:24: 9:6 core:tokio_core::reactor::Core]`
  = note: required by `std::thread::spawn`

Of course, we normally don't send Core across thread boundaries, but this is just an example. I often encounter this kind of question when using a crate for the first time. I want rustdoc to automatically generate whether a type implements Send or Sync. Maybe the information is in the section other than "Trait Implementations."

@tirr-c tirr-c changed the title Hard to find out whether a type is Send or Sync in the docs Hard to find out whether a type is Send or Sync Sep 6, 2017
@kennytm
Copy link
Member

kennytm commented Sep 6, 2017

Duplicate of #17606

@tirr-c
Copy link
Contributor Author

tirr-c commented Sep 6, 2017

Oh, I forgot to search first.

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

No branches or pull requests

2 participants