When compiling the following code:
let (get_u16, get_u32) = match result.endianess {
Endianess::Little => (u16::from_le_bytes, u32::from_le_bytes ),
Endianess::Big => (u16::from_be_bytes, u32::from_be_bytes ),
};
The compiler complains that th functions signatures are different in both arms of the match expression, even though, according to documentation, both from_le_bytes
and from_be_bytes
have the signature fn([u8; _]) -> u32
. The error it displays is the following:
error[E0308]: match arms have incompatible types
--> src/dbg/internal/elf/info.rs:85:25
|
83 | let (get_u16, get_u32) = match result.endianess {
| __________________________________-
84 | | Endianess::Little => (u16::from_le_bytes, u32::from_le_bytes ),
| | ----------------------------------------- this is found to be of type `(fn([u8; _]) -> u16 {core::num::<impl u16>::from_le_bytes}, fn([u8; _]) -> u32 {core::num::<impl u32>::from_le_bytes})`
85 | | Endianess::Big => (u16::from_be_bytes, u32::from_be_bytes ),
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn item, found a different fn item
86 | | };
| |_________- `match` arms have incompatible types
|
= note: expected type `(fn([u8; _]) -> u16 {core::num::<impl u16>::from_le_bytes}, fn([u8; _]) -> u32 {core::num::<impl u32>::from_le_bytes})`
found type `(fn([u8; _]) -> u16 {core::num::<impl u16>::from_be_bytes}, fn([u8; _]) -> u32 {core::num::<impl u32>::from_be_bytes})`
I don't know if this is a bug, desired behavior or simply the compiler being picky. Any ideas on how to solve this?