Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less Mutex poisoning #527

Merged
merged 1 commit into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Raised MSRV to 1.70.0 to remove `lazy_static` dependency
([#550](https://github.com/asomers/mockall/pull/550))

- No longer poison a Context object's internal `Mutex` when panicing. This
requires the "nightly" feature.
([#527](https://github.com/asomers/mockall/pull/527))

## [ 0.12.1 ] - 2023-12-21

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion mockall/tests/clear_expectations_on_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn too_few_calls() {

// We shouldn't panic during drop in this case. Regression test for
// https://github.com/asomers/mockall/issues/491
#[should_panic(expected = "called `Result::unwrap()` on an `Err` value: PoisonError { .. }")]
#[cfg_attr(not(feature = "nightly"), ignore)]
#[test]
fn too_many_calls() {
panic::catch_unwind(|| {
Expand Down
11 changes: 11 additions & 0 deletions mockall_derive/src/mock_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,14 @@ impl<'a> ToTokens for Context<'a> {
#[cfg(feature = "nightly_derive")]
let must_use = quote!();

#[cfg(not(feature = "nightly_derive"))]
let clear_poison = quote!();
#[cfg(feature = "nightly_derive")]
let clear_poison = quote!(
#[allow(clippy::incompatible_msrv)]
get_expectations().clear_poison();
);

quote!(
/// Manages the context for expectations of static methods.
///
Expand Down Expand Up @@ -1621,6 +1629,9 @@ impl<'a> ToTokens for Context<'a> {
impl #ty_ig Drop for Context #ty_tg #ty_wc {
fn drop(&mut self) {
if ::std::thread::panicking() {
// Clear poison since we're about to clear the Mutex's
// contents anyway.
#clear_poison
// Drain all expectations so other tests can run with a
// blank slate. But ignore errors so we don't
// double-panic.
Expand Down