-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix deselfify for trait objects with associated types
This is especially important for constructors that return impl Future<Type=Self,...>
- Loading branch information
Showing
3 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// vim: tw=80 | ||
/// A constructor that returns Self as an associated type of some other trait. | ||
/// This is very useful when working with Futures. | ||
use mockall::*; | ||
|
||
pub trait Future { | ||
type Item; | ||
type Error; | ||
} | ||
|
||
#[allow(unused)] | ||
pub struct Foo{} | ||
|
||
#[automock] | ||
impl Foo { | ||
pub fn open() -> impl Future<Item=Self, Error=i32> { | ||
struct Bar {} | ||
impl Future for Bar { | ||
type Item=Foo; | ||
type Error=i32; | ||
} | ||
Bar{} | ||
} | ||
} | ||
|
||
#[test] | ||
fn returning() { | ||
MockFoo::expect_open().returning(|| { | ||
struct Baz {} | ||
impl Future for Baz { | ||
type Item=MockFoo; | ||
type Error=i32; | ||
} | ||
Box::new(Baz{}) | ||
}); | ||
let _a = MockFoo::open(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters