sharded icon indicating copy to clipboard operation
sharded copied to clipboard

Encountered Compilation Error with ?Sized

Open lithbitren opened this issue 7 months ago • 0 comments

[dependencies]
sharded = "0.2.1"

My environment is rust 1.81.0-nightly, and I've tested this issue on both Windows 10 and Ubuntu 24.04. Including the latest sharded library version results in a compilation error. Following the compiler's suggestion to remove ?Sized + allows the program to run smoothly.

The specific error points to a line in the sharded library's source code, which can be found at:

https://github.com/nkconnor/sharded/blob/65adf3afc6cd75984af2df03d71a8f6aec0fe7d5/src/lib.rs#L123

The error details indicate:

   |
15 | fn equivalent_key<K, V>(k: &K) -> impl Fn(&(K, V)) -> bool + '_
   |                   - this type parameter needs to be `Sized`
...
19 |     move |x| k.eq(x.0.borrow())
   |           ^ doesn't have a size known at compile-time
   |
   = note: only the last element of a tuple may have a dynamically sized type
help: consider removing the `?Sized` bound to make the type parameter `Sized`
   |
17 -     K: ?Sized + Eq,
17 +     K: Eq,
   |

For more information about this error, try `rustc --explain E0277`.

lithbitren avatar Jul 23 '24 22:07 lithbitren