From e1ac2e14c2218100b7de548788ecf6d35c5fe914 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Wed, 6 Nov 2024 10:40:50 -0700 Subject: [PATCH] Suppress the clippy::ref_option warning in generated code (#618) Fixes #617 --- CHANGELOG.md | 4 ++++ mockall/tests/ref_option.rs | 7 +++++++ mockall_derive/src/mock_function.rs | 3 +++ 3 files changed, 14 insertions(+) create mode 100644 mockall/tests/ref_option.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index ded032d2..7b0d5f1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Suppress the `#[clippy::ref_option]` warning, new in Rust 1.83.0, in + generated code. + ([#618](https://github.com/asomers/mockall/pull/618)) + - When mocking functions with a closure argument, but not using `#[concretize]`, include any additional trait bounds in the trait object argument passed to `.with` and `.returning. diff --git a/mockall/tests/ref_option.rs b/mockall/tests/ref_option.rs new file mode 100644 index 00000000..c007eb0a --- /dev/null +++ b/mockall/tests/ref_option.rs @@ -0,0 +1,7 @@ +//! Mockall should suppress clippy::ref_option warnings in generated code. +#![warn(clippy::ref_option)] + +#[mockall::automock] +pub trait Store { + fn find(&self, name: Option) -> bool; +} diff --git a/mockall_derive/src/mock_function.rs b/mockall_derive/src/mock_function.rs index 09bdff85..dd458d09 100644 --- a/mockall_derive/src/mock_function.rs +++ b/mockall_derive/src/mock_function.rs @@ -979,6 +979,7 @@ impl ToTokens for Common<'_> { } #[allow(clippy::ptr_arg)] + #[allow(clippy::ref_option)] fn matches #lg (&self, #( #argnames: &#predty, )*) -> bool { self.matcher.lock().unwrap().matches(#(#argnames, )*) } @@ -1118,6 +1119,7 @@ impl ToTokens for CommonExpectationMethods<'_> { /// Validate this expectation's matcher. #[allow(clippy::ptr_arg)] + #[allow(clippy::ref_option)] fn matches #lg (&self, #(#argnames: &#predty, )*) -> bool { self.common.matches(#(#argnames, )*) } @@ -1719,6 +1721,7 @@ impl ToTokens for Matcher<'_> { } impl #ig Matcher #tg #wc { #[allow(clippy::ptr_arg)] + #[allow(clippy::ref_option)] fn matches #lg (&self, #( #argnames: &#predty, )*) -> bool { match self { Matcher::Always => true,