Skip to content

Watcher isn't Sync with --no-default-features #503

@jamessan

Description

@jamessan

Note: we may want to document and test for this, so it isn't reverted later on with a trait under the impression of usability improvements

I did add a simple test for this in src/lib.rs, where I assert that the Watcher trait is object safe. So we can't accidentally remove this feature.

Originally posted by @erickt in #336 (comment)

That only works when not using std::sync::mpsc::Sender:

$ cargo test -p notify --no-default-features
   Compiling notify v6.0.1 (notify/notify)
error[E0277]: `std::sync::mpsc::Sender<EventLoopMsg>` cannot be shared between threads safely
   --> notify/src/inotify.rs:570:13
    |
570 |     check::<INotifyWatcher>();
    |             ^^^^^^^^^^^^^^ `std::sync::mpsc::Sender<EventLoopMsg>` cannot be shared between threads safely
    |
    = help: within `INotifyWatcher`, the trait `Sync` is not implemented for `std::sync::mpsc::Sender<EventLoopMsg>`
note: required because it appears within the type `INotifyWatcher`
   --> notify/src/inotify.rs:45:12
    |
45  | pub struct INotifyWatcher {
    |            ^^^^^^^^^^^^^^
note: required by a bound in `inotify::inotify_watcher_is_send_and_sync::check`
   --> notify/src/inotify.rs:569:24
    |
569 |     fn check<T: Send + Sync>() {}
    |                        ^^^^ required by this bound in `inotify::inotify_watcher_is_send_and_sync::check`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `notify` due to previous error

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-docimprovement/fix for documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions