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

Cannot mock Send traits #15

Open
asomers opened this issue Aug 3, 2018 · 0 comments
Open

Cannot mock Send traits #15

asomers opened this issue Aug 3, 2018 · 0 comments

Comments

@asomers
Copy link

asomers commented Aug 3, 2018

mock_derive cannot mock traits that are Send. Example:

    fn send() {
        #[mock]
        pub trait A {
            fn foo(&self);
        }

        let mock = MockA::new();
        let _ = Box::new(mock) as Box<A + Send>;
    }

Gives this error:

error[E0277]: `(dyn std::ops::FnMut() + 'static)` cannot be sent between threads safely
   --> src/t_mock_derive.rs:251:17
    |
251 |         let _ = Box::new(mock) as Box<A + Send>;
    |                 ^^^^^^^^^^^^^^ `(dyn std::ops::FnMut() + 'static)` cannot be sent between threads safely                                                    
    |
    = help: the trait `std::marker::Send` is not implemented for `(dyn std::ops::FnMut() + 'static)`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::ptr::Unique<(dyn std::ops::FnMut() + 'static)>`
    = note: required because it appears within the type `std::boxed::Box<(dyn std::ops::FnMut() + 'static)>`
    = note: required because it appears within the type `std::option::Option<std::boxed::Box<(dyn std::ops::FnMut() + 'static)>>`
    = note: required because of the requirements on the impl of `std::marker::Send` for `std::sync::Mutex<std::option::Option<std::boxed::Box<(dyn std::ops::FnMut() + 'static)>>>`
    = note: required because it appears within the type `<t_mock_derive::t::MockDerive as TestSuite>::send::MockMethodForA<()>`
    = note: required because it appears within the type `std::option::Option<<t_mock_derive::t::MockDerive as TestSuite>::send::MockMethodForA<()>>`
    = note: required because it appears within the type `<t_mock_derive::t::MockDerive as TestSuite>::send::MockA`
    = note: required for the cast to the object type `dyn <t_mock_derive::t::MockDerive as TestSuite>::send::A + std::marker::Send`
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

1 participant