Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking changes (or bug) in 0.13.1 #623

Open
Vaiz opened this issue Nov 18, 2024 · 2 comments
Open

Breaking changes (or bug) in 0.13.1 #623

Vaiz opened this issue Nov 18, 2024 · 2 comments

Comments

@Vaiz
Copy link

Vaiz commented Nov 18, 2024

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>
@asomers
Copy link
Owner

asomers commented Nov 18, 2024

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?

@Vaiz
Copy link
Author

Vaiz commented Nov 19, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants