Closed
Description
I tried this code (while debugging):
async fn handle_binary(server_ref: &Ref<State>, uuid: Uuid, bytes: Bytes) -> Result<(), SendError<Packet>> {
if uuid.as_bytes() == [0xaa, 0x2a, 0x15, 0xf6, 0xca, 0xb3, 0x46, 0xdf, 0xa8, 0x28, 0x25, 0x4d, 0x96, 0x4d, 0xd8, 0x57] {
// give user fake lag
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
}
}
Where Uuid
is the corresponding type from the uuid
crate (and everything else is my types). It has an associated function as_bytes
, which returns a 16-byte slice containing the UUID. Because the right-hand-side of the comparison is not a byte slice but an array, the two expressions can't be compared and I get error E0277, shown below. Of interest is the help message at the end, which has the correct solution, but proposes a fix with invalid syntax. It should suggest placing &
before [0xaa,...
.
error[E0277]: can't compare `&[u8; 16]` with `[{integer}; 16]`
--> src/api/ws.rs:68:24
|
68 | if uuid.as_bytes() == [0xaa, 0x2a, 0x15, 0xf6, 0xca, 0xb3, 0x46, 0xdf, 0xa8, 0x28, 0x25, 0x4d, 0x96, 0x4d, 0xd8, 0x57] {
| ^^ no implementation for `&[u8; 16] == [{integer}; 16]`
|
= help: the trait `PartialEq<[{integer}; 16]>` is not implemented for `&[u8; 16]`
= help: the following other types implement trait `PartialEq<Rhs>`:
<&[B] as PartialEq<[A; N]>>
<&[FormatItem<'_>] as PartialEq<FormatItem<'_>>>
<&[OwnedFormatItem] as PartialEq<OwnedFormatItem>>
<&[T] as PartialEq<Vec<U, A>>>
<&[u8] as PartialEq<BytesMut>>
<&[u8] as PartialEq<bytes::Bytes>>
<&mut [B] as PartialEq<[A; N]>>
<&mut [T] as PartialEq<Vec<U, A>>>
and 11 others
help: convert the array to a `&[u8]` slice instead
|
68 | if uuid.as_bytes() &==[..] [0xaa, 0x2a, 0x15, 0xf6, 0xca, 0xb3, 0x46, 0xdf, 0xa8, 0x28, 0x25, 0x4d, 0x96, 0x4d, 0xd8, 0x57] {
| + ++++
Meta
rustc --version --verbose
:
rustc 1.71.0-beta.4 (dbf31f17d 2023-06-24)
binary: rustc
commit-hash: dbf31f17d020475885f50fb7d5fc15ff239843d8
commit-date: 2023-06-24
host: x86_64-unknown-linux-gnu
release: 1.71.0-beta.4
LLVM version: 16.0.5
I could not test on nightly, as I got a different compile error, apparently related to procedural macros:
Error
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
Compiling proc-macro2 v1.0.48
Compiling cc v1.0.78
Compiling parking_lot_core v0.9.5
Compiling lock_api v0.4.9
Compiling slab v0.4.7
Compiling tokio v1.23.0
Checking futures-sink v0.3.25
Compiling generic-array v0.14.6
Checking mio v0.8.5
Checking socket2 v0.4.7
error[E0422]: cannot find struct, variant or union type `LineColumn` in crate `proc_macro`
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.48/src/wrapper.rs:479:33
|
479 | let proc_macro::LineColumn { line, column } = s.start();
| ^^^^^^^^^^ not found in `proc_macro`
|
help: consider importing one of these items
|
1 + use crate::LineColumn;
|
1 + use crate::fallback::LineColumn;
|
help: if you import `LineColumn`, refer to it directly
|
479 - let proc_macro::LineColumn { line, column } = s.start();
479 + let LineColumn { line, column } = s.start();
|
error[E0422]: cannot find struct, variant or union type `LineColumn` in crate `proc_macro`
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.48/src/wrapper.rs:496:33
|
496 | let proc_macro::LineColumn { line, column } = s.end();
| ^^^^^^^^^^ not found in `proc_macro`
|
help: consider importing one of these items
|
1 + use crate::LineColumn;
|
1 + use crate::fallback::LineColumn;
|
help: if you import `LineColumn`, refer to it directly
|
496 - let proc_macro::LineColumn { line, column } = s.end();
496 + let LineColumn { line, column } = s.end();
|
error[E0635]: unknown feature `proc_macro_span_shrink`
--> /home/me/.cargo/registry/src/index.crates.io-6f17d22bba15001f/proc-macro2-1.0.48/src/lib.rs:92:30
|
92 | feature(proc_macro_span, proc_macro_span_shrink)
| ^^^^^^^^^^^^^^^^^^^^^^
Checking signal-hook-registry v1.4.0
Checking num_cpus v1.14.0
Checking parking_lot v0.12.1