mockall icon indicating copy to clipboard operation
mockall copied to clipboard

Breaking changes (or bug) in 0.13.1

Open Vaiz opened this issue 1 year ago • 2 comments

Hello,

I just updated from version 0.13.0 to the latest version, and I've encountered compilation issues with some of my code. Below is a short example of the code that successfully compiled in version 0.13.0 but fails now.

use mockall::mock;

pub trait TestTrait {
    fn call_fn<F>(&self, f: F)
    where
        F: FnOnce() -> () + Clone + 'static;
}


mock!(
    #[derive(Debug)]
    pub TestTrait {}
    
    impl TestTrait for TestTrait {    
        fn call_fn<F>(&self, f: F)
        where
            F: FnOnce() -> () + Clone + 'static,
        {
            f()
        }
    }
);

Error

error[E0225]: only auto traits can be used as additional traits in a trait object
  --> src\mock.rs:17:33
   |
17 |             F: FnOnce() -> () + Clone + 'static,
   |                --------------   ^^^^^ additional non-auto trait
   |                |
   |                first non-auto trait
   |
   = help: consider creating a new trait with all of these as supertraits and using that trait here instead: `trait NewTrait: FnOnce<()> + Clone {}`
   = note: auto-traits like `Send` and `Sync` are traits that have special properties; for more information on them, visit <https://doc.rust-lang.org/reference/special-types-and-traits.html#auto-traits>

Vaiz avatar Nov 18 '24 15:11 Vaiz

This is probably a result of #606 . And though it's annoying, the new behavior is probably the correct behavior. I'm sorry about the regression. Did you try following the compiler's advice and defining a new trait?

asomers avatar Nov 18 '24 16:11 asomers

@asomers , thank you for your reply! You were right, I was able to fix the issue by adding a super trait. However, I still believe it would be appropriate to bump the minor version of the crate, as it has a breaking change.

Vaiz avatar Nov 19 '24 15:11 Vaiz