Skip to content

Fix naming conflicts

(I also added some spaces because vscode will prompt an error.)

Previously the following code would report an error

use enum_dispatch::enum_dispatch;

use anyhow::*; // If I comment this line out, I won't get an error.

#[enum_dispatch(Tr)]
pub enum TTT {
    A,
}

pub struct A;

#[enum_dispatch] // The error occurs here
pub trait Tr {
    fn f(&self);
}
impl Tr for A {
    fn f(&self) {
        todo!()
    }
}

The following is the error message

error[E0308]: mismatched types
  --> src\sheet4\ttt.rs:12:1
   |
12 | #[enum_dispatch]
   | ^^^^^^^^^^^^^^^^
   | |
   | expected `Result<A, &str>`, found `Result<A, Error>`
   | expected `std::result::Result<A, &'static str>` because of return type
   |
   = note: expected enum `std::result::Result<_, &'static str>`
              found enum `std::result::Result<_, anyhow::Error>`
   = note: this error originates in the attribute macro `enum_dispatch` (in Nightly builds, run with -Z macro-backtrace for more info)

Merge request reports

Loading