From 754c0819125f00f382f539bdd9fb9d71c7c80fb4 Mon Sep 17 00:00:00 2001 From: Jonas Bushart Date: Wed, 17 Apr 2024 22:39:46 +0200 Subject: [PATCH] Add test that serde_conv will not trigger `clippy::ptr_arg` Relates to #320 #729 --- serde_with/src/serde_conv.rs | 4 ++++ serde_with_test/tests/serde_conv.rs | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/serde_with/src/serde_conv.rs b/serde_with/src/serde_conv.rs index 39b3f63a..e93ef79a 100644 --- a/serde_with/src/serde_conv.rs +++ b/serde_with/src/serde_conv.rs @@ -110,6 +110,10 @@ macro_rules! serde_conv { #[allow(non_camel_case_types)] $vis struct $m; + // Prevent clippy lints triggering because of the template here + // https://github.com/jonasbb/serde_with/pull/320 + // https://github.com/jonasbb/serde_with/pull/729 + #[allow(clippy::all)] const _:() = { impl $m { $vis fn serialize(x: &$t, serializer: S) -> $crate::__private__::Result diff --git a/serde_with_test/tests/serde_conv.rs b/serde_with_test/tests/serde_conv.rs index f5a956f9..0dab3ac0 100644 --- a/serde_with_test/tests/serde_conv.rs +++ b/serde_with_test/tests/serde_conv.rs @@ -34,3 +34,16 @@ fn string_to_u32( #[derive(::s::Serialize, ::s::Deserialize)] #[serde(crate = "::s")] struct S2(#[serde(with = "number")] u32); + +// Test for clippy warning clippy::ptr_arg +// warning: writing `&String` instead of `&str` involves a new object where a slice will do +// https://github.com/jonasbb/serde_with/pull/320 +// https://github.com/jonasbb/serde_with/pull/729 +serde_conv!( + pub StringAsHtml, + ::std::string::String, + |string: &str| ::std::borrow::ToOwned::to_owned(string), + |string: ::std::string::String| -> ::std::result::Result<_, ::std::convert::Infallible> { +::std::result::Result::Ok(string) + } +);