Skip to content

Can't mock Send traits #18

@asomers

Description

@asomers

Double cannot mock a trait that must be Send. Example:

    fn send() {
        pub trait A {
            fn foo(&self);
        }

        mock_trait!(
            MockA,
            foo() -> ()
        );
        impl A for MockA {
            mock_method!(foo(&self));
        }
        let mock = MockA::default();
        let _ = Box::new(mock) as Box<A + Send>;
    }

gives the following error:

error[E0277]: `std::rc::Rc<std::cell::RefCell<std::collections::HashMap<(), fn(())>>>` cannot be sent between threads safely
   --> src/t_double.rs:388:17
    |
388 |         let _ = Box::new(mock) as Box<A + Send>;
    |                 ^^^^^^^^^^^^^^ `std::rc::Rc<std::cell::RefCell<std::collections::HashMap<(), fn(())>>>` cannot be sent between threads safely               
    |
    = help: within `<t_double::t::MockDouble as TestSuite>::send::MockA`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::RefCell<std::collections::HashMap<(), fn(())>>>`
    = note: required because it appears within the type `double::Mock<(), ()>`
    = note: required because it appears within the type `<t_double::t::MockDouble as TestSuite>::send::MockA`
    = note: required for the cast to the object type `dyn <t_double::t::MockDouble as TestSuite>::send::A + std::marker::Send`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions