-
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.
Mock methods with
where Self: ...
clauses as concrete.
Previously they were treated as generic. Among other effects, this prevents "unused method expect" warnings from the latest nightly compiler. Fixes #414
- Loading branch information
Showing
4 changed files
with
100 additions
and
2 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
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,28 @@ | ||
// vim: ts=80 | ||
//! Methods with a "where Self: ..." where clause should be mocked as concrete, | ||
//! not generic. | ||
#![deny(warnings)] | ||
|
||
// Enclose the mocked trait within a non-public module. With some versions of | ||
// rustc, that causes "unused method" errors for the generic code, but not the | ||
// concrete code. | ||
// rustc 1.66.0-nightly (e7119a030 2022-09-22) | ||
mod mymod { | ||
|
||
#[mockall::automock] | ||
pub trait Server { | ||
fn version<'a>(&'a self) -> Option<&'static str> where Self: Sized; | ||
} | ||
|
||
} | ||
|
||
use mymod::{MockServer, Server}; | ||
|
||
#[test] | ||
fn return_const() { | ||
let mut mock = MockServer::new(); | ||
mock.expect_version() | ||
.return_const(None); | ||
|
||
mock.version(); | ||
} |
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