Skip to content

Creating a mock with multiple traits fails if traits share a name #600

Closed
@discosultan

Description

@discosultan

In mockall = "0.13":

use mockall::mock;

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

mod b {
    pub trait A {
        fn bar(&self);
    }
}

mock! {
    // Structure to mock
    C {}
    // First trait to implement on C
    impl a::A for C {
        fn foo(&self);
    }
    // Second trait to implement on C
    impl b::A for C {
        fn bar(&self);
    }
}

fails with:

error[E0428]: the name `__mock_MockC_A` is defined multiple times
  --> src/lib.rs:15:1
   |
15 | mock! {
   | ^^^^^
   | |
   | `__mock_MockC_A` redefined here
   | previous definition of the module `__mock_MockC_A` here
   |
   = note: `__mock_MockC_A` must be defined only once in the type namespace of this module
   = note: this error originates in the macro `mock` (in Nightly builds, run with -Z macro-backtrace for more info)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions