stevenliebregt/fun_time

`error[E0308]: `match` arms have incompatible types` when using with box

Closed this issue · 4 comments

qarmin commented
#[derive(PartialEq, Eq, Clone, Debug, Copy, Default)]
pub enum HashType {
    #[default]
    Blake3,
    Crc32,
    Xxh3,
}
impl HashType {
    #[fun_time(message = "ABC")]
    fn hasher(self: &HashType) -> Box<dyn MyHasher> {
        match self {
            HashType::Blake3 => Box::new(blake3::Hasher::new()),
            HashType::Crc32 => Box::new(crc32fast::Hasher::new()),
            HashType::Xxh3 => Box::new(Xxh3::new()),
        }
    }
}

without fun_time works works fine.

error[E0308]: `match` arms have incompatible types
   --> czkawka_core/src/duplicate.rs:43:32
    |
41  | /         match self {
42  | |             HashType::Blake3 => Box::new(blake3::Hasher::new()),
    | |                                 ------------------------------- this is found to be of type `Box<blake3::Hasher>`
43  | |             HashType::Crc32 => Box::new(crc32fast::Hasher::new()),
    | |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `blake3::Hasher`, found `crc32fast::Hasher`
44  | |             HashType::Xxh3 => Box::new(Xxh3::new()),
45  | |         }
    | |_________- `match` arms have incompatible types
    |
    = note: `crc32fast::Hasher` and `blake3::Hasher` have similar names, but are actually distinct types
note: `crc32fast::Hasher` is defined in crate `crc32fast`
   --> /home/rafal/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crc32fast-1.3.2/src/lib.rs:79:1
    |
79  | pub struct Hasher {
    | ^^^^^^^^^^^^^^^^^
note: `blake3::Hasher` is defined in crate `blake3`
   --> /home/rafal/.cargo/registry/src/index.crates.io-6f17d22bba15001f/blake3-1.5.0/src/lib.rs:965:1
    |
965 | pub struct Hasher {
    | ^^^^^^^^^^^^^^^^^


I would have to investigate this, does this work if you remove the fun_time attribute? I don't see how the attribute affects the return type to be honest.

qarmin commented

It works fine without macro.

I just started to add #[fun_time] macro to each function in app and I found that problem

Perhaps it would work if I annotate the temporary return_value with the original return type of the function. I'll try to check that out later this week