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

[0.15.x] tray_icon::Icon not Sync on Windows #184

Open
catgirlconspiracy opened this issue Aug 22, 2024 · 1 comment
Open

[0.15.x] tray_icon::Icon not Sync on Windows #184

catgirlconspiracy opened this issue Aug 22, 2024 · 1 comment

Comments

@catgirlconspiracy
Copy link

Since 0.15, tray_icon::Icon is not Sync anymore on Windows. This is easily visible in the docs for 0.15 vs 0.14. At least on Linux Icon is still Sync which makes for an awkward portability gotcha.

Test program:

fn check_sync<T: Sync>(x: T) -> T {
    x
}

fn main() {
    let icon = tray_icon::Icon::from_rgba(vec![], 0, 0).unwrap();
    check_sync(icon);
}

Compiler error (x86_64-pc-windows-gnu):

error[E0277]: `*mut c_void` cannot be shared between threads safely
   --> src/main.rs:7:16
    |
7   |     check_sync(icon);
    |     ---------- ^^^^ `*mut c_void` cannot be shared between threads safely
    |     |
    |     required by a bound introduced by this call
    |
    = help: within `tray_icon::platform_impl::platform::icon::RaiiIcon`, the trait `Sync` is not implemented for `*mut c_void`, which is required by `tray_icon::Icon: Sync`
note: required because it appears within the type `tray_icon::platform_impl::platform::icon::RaiiIcon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/platform_impl/windows/icon.rs:58:8
    |
58  | struct RaiiIcon {
    |        ^^^^^^^^
    = note: required for `Arc<tray_icon::platform_impl::platform::icon::RaiiIcon>` to implement `Sync`
note: required because it appears within the type `tray_icon::platform_impl::platform::icon::WinIcon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/platform_impl/windows/icon.rs:63:19
    |
63  | pub(crate) struct WinIcon {
    |                   ^^^^^^^
note: required because it appears within the type `tray_icon::Icon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/icon.rs:117:12
    |
117 | pub struct Icon {
    |            ^^^^
note: required by a bound in `check_sync`
   --> src/main.rs:1:18
    |
1   | fn check_sync<T: Sync>(x: T) -> T {
    |                  ^^^^ required by this bound in `check_sync`

error[E0277]: `*mut c_void` cannot be sent between threads safely
   --> src/main.rs:7:16
    |
7   |     check_sync(icon);
    |     ---------- ^^^^ `*mut c_void` cannot be sent between threads safely
    |     |
    |     required by a bound introduced by this call
    |
    = help: within `tray_icon::platform_impl::platform::icon::RaiiIcon`, the trait `Send` is not implemented for `*mut c_void`, which is required by `tray_icon::Icon: Sync`
note: required because it appears within the type `tray_icon::platform_impl::platform::icon::RaiiIcon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/platform_impl/windows/icon.rs:58:8
    |
58  | struct RaiiIcon {
    |        ^^^^^^^^
    = note: required for `Arc<tray_icon::platform_impl::platform::icon::RaiiIcon>` to implement `Sync`
note: required because it appears within the type `tray_icon::platform_impl::platform::icon::WinIcon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/platform_impl/windows/icon.rs:63:19
    |
63  | pub(crate) struct WinIcon {
    |                   ^^^^^^^
note: required because it appears within the type `tray_icon::Icon`
   --> /home/mara/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tray-icon-0.15.1/src/icon.rs:117:12
    |
117 | pub struct Icon {
    |            ^^^^
note: required by a bound in `check_sync`
   --> src/main.rs:1:18
    |
1   | fn check_sync<T: Sync>(x: T) -> T {
    |                  ^^^^ required by this bound in `check_sync`
@amrbashir
Copy link
Member

amrbashir commented Aug 26, 2024

This happened because the latest windows-sys crate update changed the HICON type from isize to *mut c_void. I think I'd prefer to keep them non sync and require them to be used in the same place as they would be used.

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