Skip to content

Commit

Permalink
Add test that serde_conv will not trigger clippy::ptr_arg (#731)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbb committed Apr 17, 2024
2 parents bb90db5 + 754c081 commit 9989d8e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions serde_with/src/serde_conv.rs
Expand Up @@ -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<S>(x: &$t, serializer: S) -> $crate::__private__::Result<S::Ok, S::Error>
Expand Down
13 changes: 13 additions & 0 deletions serde_with_test/tests/serde_conv.rs
Expand Up @@ -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)
}
);

0 comments on commit 9989d8e

Please sign in to comment.