Skip to content

Investigate Clippy warning about unsound Send impl #54

Closed
@tatsuya6502

Description

@tatsuya6502

Since Rust beta became 1.58, weekly builds have been failing with Clippy warnings. (e.g. CI #579) It can be reproduced locally by running cargo +beta clippy --features future -- -D warnings with the latest beta 1.58.

I did unsafe impl by purpose because I thought it was correct, but now Clippy is saying unsound. Investigate and address these warnings.

$ cargo +beta clippy -V 
clippy 0.1.58 (0e07bcb68b8 2021-12-04)

$ cargo +beta clippy --features future -- -D warnings

...
error: this implementation is unsound, as some fields in `Cache<K, V, S>` are `!Send`
   --> src/future/cache.rs:196:1
    |
196 | / unsafe impl<K, V, S> Send for Cache<K, V, S>
197 | | where
198 | |     K: Send + Sync,
199 | |     V: Send + Sync,
200 | |     S: Send,
201 | | {
202 | | }
    | |_^
    |
    = note: `-D clippy::non-send-fields-in-send-ty` implied by `-D warnings`
note: the type of field `base` is `!Send`
   --> src/future/cache.rs:192:5
    |
192 |     base: BaseCache<K, V, S>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^
    = help: add bounds on type parameters `K, V, S` that satisfy `BaseCache<K, V, S>: Send`
note: the type of field `value_initializer` is `!Send`
   --> src/future/cache.rs:193:5
    |
193 |     value_initializer: Arc<ValueInitializer<K, V, S>>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: add bounds on type parameters `K, V, S` that satisfy `Arc<ValueInitializer<K, V, S>>: Send`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty

error: this implementation is unsound, as some fields in `Cache<K, V, S>` are `!Send`
   --> src/sync/cache.rs:168:1
    |
168 | / unsafe impl<K, V, S> Send for Cache<K, V, S>
169 | | where
170 | |     K: Send + Sync,
171 | |     V: Send + Sync,
172 | |     S: Send,
173 | | {
174 | | }
    | |_^
    |
note: the type of field `base` is `!Send`
   --> src/sync/cache.rs:164:5
    |
164 |     base: BaseCache<K, V, S>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^
    = help: add bounds on type parameters `K, V, S` that satisfy `BaseCache<K, V, S>: Send`
note: the type of field `value_initializer` is `!Send`
   --> src/sync/cache.rs:165:5
    |
165 |     value_initializer: Arc<ValueInitializer<K, V, S>>,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    = help: add bounds on type parameters `K, V, S` that satisfy `Arc<ValueInitializer<K, V, S>>: Send`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty

error: this implementation is unsound, as some fields in `Deques<K>` are `!Send`
  --> src/sync/deques.rs:17:1
   |
17 | unsafe impl<K> Send for Deques<K> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
note: the type of field `window` is `!Send`
  --> src/sync/deques.rs:7:5
   |
7  |     pub(crate) window: Deque<KeyHashDate<K>>, //    Not used yet.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: add bounds on type parameter `K` that satisfy `Deque<KeyHashDate<K>>: Send`
note: the type of field `probation` is `!Send`
  --> src/sync/deques.rs:8:5
   |
8  |     pub(crate) probation: Deque<KeyHashDate<K>>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: add bounds on type parameter `K` that satisfy `Deque<KeyHashDate<K>>: Send`
note: the type of field `protected` is `!Send`
  --> src/sync/deques.rs:9:5
   |
9  |     pub(crate) protected: Deque<KeyHashDate<K>>, // Not used yet.
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: add bounds on type parameter `K` that satisfy `Deque<KeyHashDate<K>>: Send`
note: the type of field `write_order` is `!Send`
  --> src/sync/deques.rs:10:5
   |
10 |     pub(crate) write_order: Deque<KeyDate<K>>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: add bounds on type parameter `K` that satisfy `Deque<KeyDate<K>>: Send`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty

error: this implementation is unsound, as some fields in `SegmentedCache<K, V, S>` are `!Send`
  --> src/sync/segment.rs:27:1
   |
27 | / unsafe impl<K, V, S> Send for SegmentedCache<K, V, S>
28 | | where
29 | |     K: Send + Sync,
30 | |     V: Send + Sync,
31 | |     S: Send,
32 | | {
33 | | }
   | |_^
   |
note: the type of field `inner` is `!Send`
  --> src/sync/segment.rs:24:5
   |
24 |     inner: Arc<Inner<K, V, S>>,
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: add bounds on type parameters `K, V, S` that satisfy `Arc<Inner<K, V, S>>: Send`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty

error: could not compile `moka` due to 4 previous errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions