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

gtk: Clippy warns about unsound Send implementation #2067

Open
jplatte opened this issue Dec 3, 2021 · 4 comments
Open

gtk: Clippy warns about unsound Send implementation #2067

jplatte opened this issue Dec 3, 2021 · 4 comments
Labels
shell/gtk concerns the GTK backend

Comments

@jplatte
Copy link
Member

jplatte commented Dec 3, 2021

Nightly clippy raises the following warning:

warning: this implementation is unsound, as some fields in `WindowState` are `!Send`
    --> druid-shell/src/backend/gtk/window.rs:1271:1
     |
1271 | unsafe impl Send for WindowState {}
     | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(clippy::non_send_fields_in_send_ty)]` on by default
note: the type of field `window` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:173:5
     |
173  |     window: ApplicationWindow,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
note: the type of field `drawing_area` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:180:5
     |
180  |     drawing_area: DrawingArea,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
note: the type of field `surface` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:191:5
     |
191  |     surface: RefCell<Option<Surface>>,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
note: the type of field `handler` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:196:5
     |
196  |     pub(crate) handler: RefCell<Box<dyn WinHandler>>,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
note: the type of field `deferred_queue` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:201:5
     |
201  |     deferred_queue: RefCell<Vec<DeferredOp>>,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
note: the type of field `parent` is `!Send`
    --> druid-shell/src/backend/gtk/window.rs:206:5
     |
206  |     parent: Option<crate::WindowHandle>,
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     = help: use a thread-safe type that implements `Send`
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
@maan2003
Copy link
Collaborator

maan2003 commented Dec 3, 2021

The comment explains why it is safe for our case:

// WindowState needs to be Send + Sync so it can be passed into glib closures.
// TODO: can we localize the unsafety more? Glib's idle loop always runs on the main thread,
// and we always construct the WindowState on the main thread, so it should be ok (and also
// WindowState isn't a public type).
unsafe impl Send for WindowState {}

@maan2003
Copy link
Collaborator

maan2003 commented Dec 3, 2021

There is also a warning on mac backend 😬

@maan2003 maan2003 added shell/gtk concerns the GTK backend shell/mac concerns the macOS backend labels Dec 3, 2021
@jplatte
Copy link
Member Author

jplatte commented Dec 3, 2021

I don't care about that one 😋

Should probably be a separate issue so it's clear that the gtk issue is fixed once my associated PR is merged?

@maan2003
Copy link
Collaborator

maan2003 commented Dec 3, 2021

Sure, done #2069

@maan2003 maan2003 removed the shell/mac concerns the macOS backend label Dec 3, 2021
@jplatte jplatte changed the title Clippy warns about unsound Send implementation gtk: Clippy warns about unsound Send implementation Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
shell/gtk concerns the GTK backend
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants