-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
automock wrongly removes elided lifetimes from structs Issue #610
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// vim: tw=80 | ||
//! Mock a struct with a lifetime parameter | ||
#![deny(warnings)] | ||
|
||
use mockall::*; | ||
|
||
pub struct NonStaticStruct<'nss> { | ||
_x: &'nss i32 | ||
} | ||
|
||
#[automock] | ||
impl NonStaticStruct<'_> { | ||
pub fn foo(&self) -> i64 { | ||
42 | ||
} | ||
} | ||
|
||
#[test] | ||
fn normal_method() { | ||
// This function serves to define a named lifetime | ||
fn has_lt<'a>(_x: &'a i8) -> MockNonStaticStruct<'a> { | ||
MockNonStaticStruct::<'a>::default() | ||
} | ||
|
||
let x = 42i8; | ||
let mut mock = has_lt(&x); | ||
mock.expect_foo() | ||
.returning(|| 5); | ||
assert_eq!(5, mock.foo()); | ||
} |