linebender / druid

A data-first Rust-native UI design toolkit.
https://linebender.org/druid/
Apache License 2.0
9.43k stars 568 forks source link

gtk: Clippy warns about unsound `Send` implementation #2067

Open jplatte opened 2 years ago

jplatte commented 2 years ago

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 commented 2 years ago

The comment explains why it is safe for our case:

https://github.com/linebender/druid/blob/782d25e1feb29074dd2cfe483ef52fcd91dae391/druid-shell/src/backend/gtk/window.rs#L1267-L1271

maan2003 commented 2 years ago

There is also a warning on mac backend :grimacing:

jplatte commented 2 years ago

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 commented 2 years ago

Sure, done #2069